@forgepack/request 1.0.14 → 1.1.1

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
@@ -9,7 +9,7 @@
9
9
 
10
10
  [![React](https://img.shields.io/badge/React-19.2.0-61DAFB?logo=react)](https://react.dev/)
11
11
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.9.3-blue?logo=typescript)](https://www.typescriptlang.org/)
12
- [![Axios](https://img.shields.io/badge/Axios-Latest-5A29E4?logo=axios)](https://axios-http.com/)
12
+ [![Fetch API](https://img.shields.io/badge/Fetch_API-Native-5A29E4?logo=javascript)](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
13
13
 
14
14
  [Documentation](https://forgepack.dev/packages/request) • [NPM Package](https://www.npmjs.com/package/@forgepack/request) • [GitHub](https://github.com/forgepack/request) • [Report Bug](https://github.com/forgepack/request/issues)
15
15
 
@@ -29,7 +29,7 @@
29
29
 
30
30
  ## Description
31
31
 
32
- `@forgepack/request` is a complete, opinionated HTTP client built on top of Axios for React applications. It provides automatic JWT authentication, request/response interceptors, React hooks for state management, and standardized CRUD operations—everything you need to handle API communication in modern React apps.
32
+ `@forgepack/request` is a complete, opinionated HTTP client built on top of the native Fetch API for React applications. It provides automatic JWT authentication, request/response interceptors, React hooks for state management, and standardized CRUD operations—everything you need to handle API communication in modern React apps.
33
33
 
34
34
  **Perfect for:** Teams building React applications with JWT-based backends who want a plug-and-play solution that handles authentication, authorization, and API requests with minimal boilerplate.
35
35
 
@@ -54,7 +54,6 @@ Make sure you have these installed:
54
54
  {
55
55
  "react": ">=16.8.0",
56
56
  "react-dom": ">=16.8.0",
57
- "axios": ">=1.0.0",
58
57
  "react-router-dom": ">=6.0.0" // Optional, only if using RequireAuth
59
58
  }
60
59
  ```
@@ -1,4 +1,3 @@
1
- import { AxiosInstance } from "axios";
2
1
  /**
3
2
  * Configuration options for the API client
4
3
  * @interface ApiClientOptions
@@ -12,13 +11,59 @@ export type ApiClientOptions = {
12
11
  onForbidden?: () => void;
13
12
  };
14
13
  /**
15
- * Creates a configured Axios client instance with interceptors for JWT authentication and error handling
14
+ * Response structure that mimics axios response
15
+ */
16
+ export type HttpResponse<T = any> = {
17
+ data: T;
18
+ status: number;
19
+ statusText: string;
20
+ headers: Record<string, string>;
21
+ };
22
+ /**
23
+ * Error structure that mimics axios error
24
+ */
25
+ export type HttpError = Error & {
26
+ response?: {
27
+ data?: any;
28
+ status?: number;
29
+ statusText?: string;
30
+ };
31
+ };
32
+ /**
33
+ * API Client instance that provides HTTP methods similar to axios
34
+ */
35
+ export interface ApiInstance {
36
+ baseURL: string;
37
+ get<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
38
+ post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
39
+ put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
40
+ delete<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
41
+ patch<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
42
+ interceptors: {
43
+ request: {
44
+ use: (onFulfilled: (config: RequestConfig) => Promise<RequestConfig>) => void;
45
+ };
46
+ response: {
47
+ use: (onFulfilled: (response: HttpResponse) => HttpResponse, onRejected: (error: HttpError) => Promise<never>) => void;
48
+ };
49
+ };
50
+ }
51
+ /**
52
+ * Request configuration that mimics axios config
53
+ */
54
+ export type RequestConfig = {
55
+ params?: Record<string, any>;
56
+ headers?: Record<string, string>;
57
+ signal?: AbortSignal;
58
+ };
59
+ /**
60
+ * Creates a configured Fetch-based client instance with interceptors for JWT authentication and error handling
16
61
  *
17
62
  * @param {ApiClientOptions} options - Client configuration options
18
63
  * @param {string} options.baseURL - Base URL for all API requests
19
64
  * @param {Function} [options.onUnauthorized] - Optional callback for 401 errors
20
65
  * @param {Function} [options.onForbidden] - Optional callback for 403 errors
21
- * @returns {AxiosInstance} Configured Axios instance with request/response interceptors
66
+ * @returns {ApiInstance} Configured API instance with request/response interceptors
22
67
  *
23
68
  * @example
24
69
  * ```typescript
@@ -33,5 +78,5 @@ export type ApiClientOptions = {
33
78
  * })
34
79
  * ```
35
80
  */
36
- export declare const createApiClient: (options: ApiClientOptions) => AxiosInstance;
81
+ export declare const createApiClient: (options: ApiClientOptions) => ApiInstance;
37
82
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAG5C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAA;IACf,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,4GAA4G;IAC5G,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;CAC3B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,aA+B3D,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAA;IACf,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,4GAA4G;IAC5G,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI;IAChC,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC,CAAA;AAED;;GAEG;AACH,M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,EAAE;YACN,GAAG,EAAE,CACD,WAAW,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,YAAY,EACrD,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,KAAK,CAAC,KAC/C,IAAI,CAAA;SACZ,CAAA;KACJ,CAAA;CACJ;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,WAsM3D,CAAA"}
@@ -1,19 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.createApiClient = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const token_1 = require("../services/token");
9
5
  /**
10
- * Creates a configured Axios client instance with interceptors for JWT authentication and error handling
6
+ * Creates a configured Fetch-based client instance with interceptors for JWT authentication and error handling
11
7
  *
12
8
  * @param {ApiClientOptions} options - Client configuration options
13
9
  * @param {string} options.baseURL - Base URL for all API requests
14
10
  * @param {Function} [options.onUnauthorized] - Optional callback for 401 errors
15
11
  * @param {Function} [options.onForbidden] - Optional callback for 403 errors
16
- * @returns {AxiosInstance} Configured Axios instance with request/response interceptors
12
+ * @returns {ApiInstance} Configured API instance with request/response interceptors
17
13
  *
18
14
  * @example
19
15
  * ```typescript
@@ -29,22 +25,151 @@ const token_1 = require("../services/token");
29
25
  * ```
30
26
  */
31
27
  const createApiClient = (options) => {
32
- /** Create base Axios instance with default configuration */
33
- const api = axios_1.default.create({
34
- baseURL: options.baseURL,
35
- headers: { 'content-type': 'application/json' }
36
- });
37
- /** Request interceptor: Add JWT token to all requests */
38
- api.interceptors.request.use(async (config) => {
28
+ let requestInterceptor = null;
29
+ let responseInterceptor = null;
30
+ /**
31
+ * Build URL with parameters
32
+ */
33
+ const buildUrl = (endpoint, params) => {
34
+ const url = new URL(endpoint.startsWith('/') ? endpoint.slice(1) : endpoint, options.baseURL);
35
+ if (params) {
36
+ Object.entries(params).forEach(([key, value]) => {
37
+ if (value !== undefined && value !== null) {
38
+ url.searchParams.append(key, String(value));
39
+ }
40
+ });
41
+ }
42
+ return url.toString();
43
+ };
44
+ /**
45
+ * Convert Headers to plain object
46
+ */
47
+ const headersToObject = (headers) => {
48
+ const result = {};
49
+ headers.forEach((value, key) => {
50
+ result[key] = value;
51
+ });
52
+ return result;
53
+ };
54
+ /**
55
+ * Make HTTP request using fetch
56
+ */
57
+ const makeRequest = async (method, url, data, config = {}) => {
39
58
  var _a;
59
+ /** Apply request interceptor */
60
+ if (requestInterceptor) {
61
+ config = await requestInterceptor(config);
62
+ }
63
+ const fullUrl = buildUrl(url, config.params);
64
+ const headers = {
65
+ 'Content-Type': 'application/json',
66
+ ...config.headers
67
+ };
68
+ /** Add JWT token if available */
40
69
  const token = (_a = (0, token_1.getToken)()) === null || _a === void 0 ? void 0 : _a.accessToken;
41
70
  if (token) {
42
- config.headers.Authorization = `Bearer ${token}`;
71
+ headers.Authorization = `Bearer ${token}`;
43
72
  }
44
- return config;
45
- });
73
+ let body;
74
+ if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
75
+ body = JSON.stringify(data);
76
+ }
77
+ try {
78
+ const response = await fetch(fullUrl, {
79
+ method,
80
+ headers,
81
+ body,
82
+ signal: config.signal
83
+ });
84
+ const responseData = await (async () => {
85
+ const text = await response.text();
86
+ try {
87
+ return text ? JSON.parse(text) : null;
88
+ }
89
+ catch {
90
+ return text;
91
+ }
92
+ })();
93
+ const apiResponse = {
94
+ data: responseData,
95
+ status: response.status,
96
+ statusText: response.statusText,
97
+ headers: headersToObject(response.headers)
98
+ };
99
+ if (!response.ok) {
100
+ const error = new Error(`HTTP Error: ${response.status}`);
101
+ error.response = {
102
+ data: responseData,
103
+ status: response.status,
104
+ statusText: response.statusText
105
+ };
106
+ /** Apply response interceptor for errors */
107
+ if (responseInterceptor) {
108
+ return await responseInterceptor.onRejected(error);
109
+ }
110
+ throw error;
111
+ }
112
+ /** Apply response interceptor for success */
113
+ if (responseInterceptor) {
114
+ return responseInterceptor.onFulfilled(apiResponse);
115
+ }
116
+ return apiResponse;
117
+ }
118
+ catch (error) {
119
+ if (error.name === 'AbortError') {
120
+ const abortError = new Error('Request was aborted');
121
+ abortError.response = {
122
+ status: 0,
123
+ statusText: 'Request Aborted'
124
+ };
125
+ throw abortError;
126
+ }
127
+ if (error.response) {
128
+ /** Error already formatted by our code above */
129
+ throw error;
130
+ }
131
+ /** Network or other errors */
132
+ const networkError = new Error(error.message || 'Network Error');
133
+ networkError.response = {
134
+ status: 0,
135
+ statusText: 'Network Error'
136
+ };
137
+ throw networkError;
138
+ }
139
+ };
140
+ /** Create the API instance */
141
+ const api = {
142
+ baseURL: options.baseURL,
143
+ get(url, config) {
144
+ return makeRequest('GET', url, undefined, config);
145
+ },
146
+ post(url, data, config) {
147
+ return makeRequest('POST', url, data, config);
148
+ },
149
+ put(url, data, config) {
150
+ return makeRequest('PUT', url, data, config);
151
+ },
152
+ delete(url, config) {
153
+ return makeRequest('DELETE', url, undefined, config);
154
+ },
155
+ patch(url, data, config) {
156
+ return makeRequest('PATCH', url, data, config);
157
+ },
158
+ interceptors: {
159
+ request: {
160
+ use: (onFulfilled) => {
161
+ requestInterceptor = onFulfilled;
162
+ }
163
+ },
164
+ response: {
165
+ use: (onFulfilled, onRejected) => {
166
+ responseInterceptor = { onFulfilled, onRejected };
167
+ }
168
+ }
169
+ }
170
+ };
46
171
  /** Response interceptor: Handle authentication and authorization errors */
47
- api.interceptors.response.use((response) => response, (error) => {
172
+ api.interceptors.response.use((response) => response, async (error) => {
48
173
  var _a, _b, _c, _d;
49
174
  /** Handle 401 Unauthorized errors: Token invalid/expired */
50
175
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
@@ -1,10 +1,10 @@
1
- import { AxiosInstance } from 'axios';
1
+ import { ApiInstance } from '../api/client';
2
2
  /**
3
3
  * Properties of the AuthProvider
4
4
  */
5
5
  export type AuthProviderProps = {
6
- /** Axios instance for requests */
7
- api: AxiosInstance;
6
+ /** API instance for requests */
7
+ api: ApiInstance;
8
8
  /** Child components that will receive the context */
9
9
  children: React.ReactNode;
10
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../src/hooks/AuthProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAGrC;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,kCAAkC;IAClC,GAAG,EAAE,aAAa,CAAA;IAClB,qDAAqD;IACrD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,eAAO,MAAM,YAAY,GAAI,mBAAmB,iBAAiB,4CAiDhE,CAAA"}
1
+ {"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../src/hooks/AuthProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,gCAAgC;IAChC,GAAG,EAAE,WAAW,CAAA;IAChB,qDAAqD;IACrD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,eAAO,MAAM,YAAY,GAAI,mBAAmB,iBAAiB,4CAiDhE,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { ErrorMessage } from '../types/error';
2
2
  import { Page } from '../types/response';
3
3
  import { Search } from '../types/request';
4
- import { AxiosInstance } from 'axios';
4
+ import { ApiInstance } from '../api/client';
5
5
  /**
6
6
  * Return type of the useRequest hook
7
7
  */
@@ -25,7 +25,7 @@ export type UseRequestReturn = {
25
25
  * - Automatic re-execution when endpoint or search parameters change
26
26
  * - Request deduplication via AbortController
27
27
  *
28
- * @param {AxiosInstance} api - Configured Axios instance with authentication
28
+ * @param {ApiInstance} api - Configured API instance with authentication
29
29
  * @param {string} endpoint - API endpoint path (without leading slash, e.g., 'users' or 'posts')
30
30
  * @param {Search} [search] - Optional search and pagination parameters
31
31
  * @param {number} [search.page] - Page number (zero-indexed)
@@ -53,5 +53,5 @@ export type UseRequestReturn = {
53
53
  * await request()
54
54
  * ```
55
55
  */
56
- export declare const useRequest: (api: AxiosInstance, endpoint: string, search?: Search) => UseRequestReturn;
56
+ export declare const useRequest: (api: ApiInstance, endpoint: string, search?: Search) => UseRequestReturn;
57
57
  //# sourceMappingURL=useRequest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRequest.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,2CAA2C;IAC3C,QAAQ,EAAE,IAAI,CAAA;IACd,gDAAgD;IAChD,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,iDAAiD;IACjD,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,eAAO,MAAM,UAAU,GAAI,KAAK,aAAa,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,gBAyClF,CAAA"}
1
+ {"version":3,"file":"useRequest.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,2CAA2C;IAC3C,QAAQ,EAAE,IAAI,CAAA;IACd,gDAAgD;IAChD,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,iDAAiD;IACjD,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,eAAO,MAAM,UAAU,GAAI,KAAK,WAAW,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,gBAyChF,CAAA"}
@@ -14,7 +14,7 @@ const api_1 = require("../services/api");
14
14
  * - Automatic re-execution when endpoint or search parameters change
15
15
  * - Request deduplication via AbortController
16
16
  *
17
- * @param {AxiosInstance} api - Configured Axios instance with authentication
17
+ * @param {ApiInstance} api - Configured API instance with authentication
18
18
  * @param {string} endpoint - API endpoint path (without leading slash, e.g., 'users' or 'posts')
19
19
  * @param {Search} [search] - Optional search and pagination parameters
20
20
  * @param {number} [search.page] - Page number (zero-indexed)
package/dist/index.d.ts CHANGED
@@ -69,7 +69,7 @@
69
69
  *
70
70
  * @fileoverview React package for managing HTTP requests with JWT authentication
71
71
  * @author Marcelo Gadelha {@link https://github.com/gadelhati}
72
- * @version 1.0.13
72
+ * @version 1.1.1
73
73
  * @license MIT License
74
74
  *
75
75
  * @remarks
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@
70
70
  *
71
71
  * @fileoverview React package for managing HTTP requests with JWT authentication
72
72
  * @author Marcelo Gadelha {@link https://github.com/gadelhati}
73
- * @version 1.0.13
73
+ * @version 1.1.1
74
74
  * @license MIT License
75
75
  *
76
76
  * @remarks
@@ -1,4 +1,4 @@
1
- import { AxiosInstance } from 'axios';
1
+ import { ApiInstance } from '../api/client';
2
2
  import { Page } from '../types/response';
3
3
  import { Search } from '../types/request';
4
4
  /**
@@ -11,7 +11,7 @@ import { Search } from '../types/request';
11
11
  * - Request cancellation via AbortSignal
12
12
  * - Automatic URL encoding for search values
13
13
  *
14
- * @param {AxiosInstance} api - Configured Axios instance with authentication and base URL
14
+ * @param {ApiInstance} api - Configured API instance with authentication and base URL
15
15
  * @param {string} endpoint - API endpoint path (without leading slash, e.g., 'users' or 'posts')
16
16
  * @param {Search} [search] - Optional search, pagination and sorting parameters
17
17
  * @param {number} [search.page] - Page number (zero-indexed, default handled by backend)
@@ -23,7 +23,7 @@ import { Search } from '../types/request';
23
23
  * @param {AbortSignal} [signal] - Signal for request cancellation (from AbortController)
24
24
  * @returns {Promise<Page>} Promise resolving to paginated response data
25
25
  *
26
- * @throws {AxiosError} When the HTTP request fails
26
+ * @throws {Error} When the HTTP request fails
27
27
  * @throws {Error} When request is aborted via signal
28
28
  *
29
29
  * @example
@@ -51,5 +51,5 @@ import { Search } from '../types/request';
51
51
  * controller.abort()
52
52
  * ```
53
53
  */
54
- export declare const fetchPage: <T>(api: AxiosInstance, endpoint: string, search?: Search, signal?: AbortSignal) => Promise<Page<T>>;
54
+ export declare const fetchPage: <T>(api: ApiInstance, endpoint: string, search?: Search, signal?: AbortSignal) => Promise<Page<T>>;
55
55
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,EAAG,KAAK,aAAa,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,EAAE,SAAS,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAqBhI,CAAA"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,EAAG,KAAK,WAAW,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,EAAE,SAAS,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAqB9H,CAAA"}
@@ -11,7 +11,7 @@ exports.fetchPage = void 0;
11
11
  * - Request cancellation via AbortSignal
12
12
  * - Automatic URL encoding for search values
13
13
  *
14
- * @param {AxiosInstance} api - Configured Axios instance with authentication and base URL
14
+ * @param {ApiInstance} api - Configured API instance with authentication and base URL
15
15
  * @param {string} endpoint - API endpoint path (without leading slash, e.g., 'users' or 'posts')
16
16
  * @param {Search} [search] - Optional search, pagination and sorting parameters
17
17
  * @param {number} [search.page] - Page number (zero-indexed, default handled by backend)
@@ -23,7 +23,7 @@ exports.fetchPage = void 0;
23
23
  * @param {AbortSignal} [signal] - Signal for request cancellation (from AbortController)
24
24
  * @returns {Promise<Page>} Promise resolving to paginated response data
25
25
  *
26
- * @throws {AxiosError} When the HTTP request fails
26
+ * @throws {Error} When the HTTP request fails
27
27
  * @throws {Error} When request is aborted via signal
28
28
  *
29
29
  * @example
@@ -1,10 +1,10 @@
1
- import { AxiosInstance } from 'axios';
1
+ import { ApiInstance } from '../api/client';
2
2
  import { ErrorMessage } from '../types/error';
3
3
  import { LoginCredentials, LoginResponse, ChangePasswordData, ResetPasswordData } from '../types/auth';
4
4
  /**
5
5
  * Performs user login and stores the returned token
6
6
  *
7
- * @param {AxiosInstance} api - Configured Axios instance with base URL
7
+ * @param {ApiInstance} api - Configured API instance with base URL
8
8
  * @param {string} url - Login endpoint path (e.g., '/auth/login')
9
9
  * @param {LoginCredentials} credentials - User login credentials
10
10
  * @param {string} credentials.username - Username or email
@@ -32,11 +32,11 @@ import { LoginCredentials, LoginResponse, ChangePasswordData, ResetPasswordData
32
32
  * }
33
33
  * ```
34
34
  */
35
- export declare const login: (api: AxiosInstance, url: string, credentials: LoginCredentials) => Promise<LoginResponse>;
35
+ export declare const login: (api: ApiInstance, url: string, credentials: LoginCredentials) => Promise<LoginResponse>;
36
36
  /**
37
37
  * Performs password reset using a reset token and updates authentication
38
38
  *
39
- * @param {AxiosInstance} api - Configured Axios instance
39
+ * @param {ApiInstance} api - Configured API instance
40
40
  * @param {string} url - Password reset endpoint path (e.g., '/auth/reset-password')
41
41
  * @param {ResetPasswordData} data - Password reset data
42
42
  * @param {string} data.token - Password reset token (from email)
@@ -49,7 +49,7 @@ export declare const login: (api: AxiosInstance, url: string, credentials: Login
49
49
  * ```typescript
50
50
  * ```
51
51
  */
52
- export declare const reset: (api: AxiosInstance, url: string, data: ResetPasswordData) => Promise<LoginResponse>;
52
+ export declare const reset: (api: ApiInstance, url: string, data: ResetPasswordData) => Promise<LoginResponse>;
53
53
  /**
54
54
  * Logs out the current user by removing authentication data from localStorage
55
55
  *
@@ -72,7 +72,7 @@ export declare const logout: () => void;
72
72
  * Requires user to be authenticated (valid token in localStorage).
73
73
  * User must provide current password for verification.
74
74
  *
75
- * @param {AxiosInstance} api - Configured Axios instance with authentication
75
+ * @param {ApiInstance} api - Configured API instance with authentication
76
76
  * @param {ChangePasswordData} data - Password change data
77
77
  * @param {string} data.currentPassword - Current password for verification
78
78
  * @param {string} data.newPassword - New password to set
@@ -101,7 +101,7 @@ export declare const logout: () => void;
101
101
  * }
102
102
  * ```
103
103
  */
104
- export declare const changePassword: (api: AxiosInstance, data: ChangePasswordData) => Promise<{
104
+ export declare const changePassword: (api: ApiInstance, data: ChangePasswordData) => Promise<{
105
105
  success: boolean;
106
106
  errors?: ErrorMessage[];
107
107
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAQ,gBAAgB,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAuC5G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,KAAK,GAAU,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,aAAa,gBAAgB,KAAG,OAAO,CAAC,aAAa,CAcjH,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK,GAAU,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,KAAG,OAAO,CAAC,aAAa,CAc3G,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM,YAElB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,cAAc,GAAU,KAAK,aAAa,EAAE,MAAM,kBAAkB,KAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;CAAE,CAUxI,CAAA"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAQ,gBAAgB,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAuC5G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,KAAK,GAAU,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,aAAa,gBAAgB,KAAG,OAAO,CAAC,aAAa,CAc/G,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK,GAAU,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,KAAG,OAAO,CAAC,aAAa,CAczG,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM,YAElB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,cAAc,GAAU,KAAK,WAAW,EAAE,MAAM,kBAAkB,KAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;CAAE,CAUtI,CAAA"}
@@ -5,7 +5,7 @@ const token_1 = require("./token");
5
5
  /**
6
6
  * Processes API response errors and converts them to standardized format
7
7
  *
8
- * @param {any} error - Axios error object
8
+ * @param {any} error - API error object
9
9
  * @returns {ErrorMessage[]} Array of formatted error messages with field and message properties
10
10
  *
11
11
  * @internal This is a utility function used internally by auth service methods
@@ -42,7 +42,7 @@ const addError = (error) => {
42
42
  /**
43
43
  * Performs user login and stores the returned token
44
44
  *
45
- * @param {AxiosInstance} api - Configured Axios instance with base URL
45
+ * @param {ApiInstance} api - Configured API instance with base URL
46
46
  * @param {string} url - Login endpoint path (e.g., '/auth/login')
47
47
  * @param {LoginCredentials} credentials - User login credentials
48
48
  * @param {string} credentials.username - Username or email
@@ -90,7 +90,7 @@ exports.login = login;
90
90
  /**
91
91
  * Performs password reset using a reset token and updates authentication
92
92
  *
93
- * @param {AxiosInstance} api - Configured Axios instance
93
+ * @param {ApiInstance} api - Configured API instance
94
94
  * @param {string} url - Password reset endpoint path (e.g., '/auth/reset-password')
95
95
  * @param {ResetPasswordData} data - Password reset data
96
96
  * @param {string} data.token - Password reset token (from email)
@@ -145,7 +145,7 @@ exports.logout = logout;
145
145
  * Requires user to be authenticated (valid token in localStorage).
146
146
  * User must provide current password for verification.
147
147
  *
148
- * @param {AxiosInstance} api - Configured Axios instance with authentication
148
+ * @param {ApiInstance} api - Configured API instance with authentication
149
149
  * @param {ChangePasswordData} data - Password change data
150
150
  * @param {string} data.currentPassword - Current password for verification
151
151
  * @param {string} data.newPassword - New password to set
@@ -1,4 +1,4 @@
1
- import { AxiosInstance } from 'axios';
1
+ import { ApiInstance } from '../api/client';
2
2
  import { ErrorMessage } from '../types/error';
3
3
  import { Search } from '../types/request';
4
4
  import { Page } from '../types/response';
@@ -6,7 +6,7 @@ import { Page } from '../types/response';
6
6
  * Creates a new record in the API via POST request
7
7
  *
8
8
  * @template T - Type of object to be created
9
- * @param {AxiosInstance} api - Configured Axios instance with authentication
9
+ * @param {ApiInstance} api - Configured API instance with authentication
10
10
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
11
11
  * @param {T} object - Object data to be created
12
12
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to created data or array of errors
@@ -19,12 +19,12 @@ import { Page } from '../types/response';
19
19
  * const result = await create(api, 'users', { name: 'John Snow', email: 'john@example.com', role: 'USER' })
20
20
  * ```
21
21
  */
22
- export declare const create: <T>(api: AxiosInstance, url: string, object: T) => Promise<T | ErrorMessage[]>;
22
+ export declare const create: <T>(api: ApiInstance, url: string, object: T) => Promise<T | ErrorMessage[]>;
23
23
  /**
24
24
  * Creates multiple records at once in the API via batch POST request
25
25
  *
26
26
  * @template T - Type of objects to be created
27
- * @param {AxiosInstance} api - Configured Axios instance with authentication
27
+ * @param {ApiInstance} api - Configured API instance with authentication
28
28
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
29
29
  * @param {T[]} object - Array of objects to be created
30
30
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to created data or array of errors
@@ -43,7 +43,7 @@ export declare const create: <T>(api: AxiosInstance, url: string, object: T) =>
43
43
  * const result = await createAll(api, 'users', users)
44
44
  * ```
45
45
  */
46
- export declare const createAll: <T>(api: AxiosInstance, url: string, object: T[]) => Promise<T | ErrorMessage[]>;
46
+ export declare const createAll: <T>(api: ApiInstance, url: string, object: T[]) => Promise<T | ErrorMessage[]>;
47
47
  /**
48
48
  * Retrieves records from the API with optional pagination, search, and sorting support
49
49
  *
@@ -56,7 +56,7 @@ export declare const createAll: <T>(api: AxiosInstance, url: string, object: T[]
56
56
  * - With sort: paginated and sorted search
57
57
  *
58
58
  * @template T - Type of individual items in the response
59
- * @param {AxiosInstance} api - Configured Axios instance with authentication
59
+ * @param {ApiInstance} api - Configured API instance with authentication
60
60
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
61
61
  * @param {Search} [search] - Optional search, pagination and sorting parameters
62
62
  * @param {number} [search.page] - Page number (zero-indexed)
@@ -94,12 +94,12 @@ export declare const createAll: <T>(api: AxiosInstance, url: string, object: T[]
94
94
  * const promise = retrieve(api, 'posts', { page: 0, size: 15 }, controller.signal)
95
95
  * ```
96
96
  */
97
- export declare const retrieve: <T>(api: AxiosInstance, url: string, search?: Search, signal?: AbortSignal) => Promise<Page<T> | ErrorMessage[]>;
97
+ export declare const retrieve: <T>(api: ApiInstance, url: string, search?: Search, signal?: AbortSignal) => Promise<Page<T> | ErrorMessage[]>;
98
98
  /**
99
99
  * Updates an existing record in the API via PUT request
100
100
  *
101
101
  * @template T - Type of object to be updated
102
- * @param {AxiosInstance} api - Configured Axios instance with authentication
102
+ * @param {ApiInstance} api - Configured API instance with authentication
103
103
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
104
104
  * @param {T} object - Updated object data (must include identifier)
105
105
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to response or array of errors
@@ -111,12 +111,12 @@ export declare const retrieve: <T>(api: AxiosInstance, url: string, search?: Sea
111
111
  * const result = await update(api, 'users', { id: 1, name: 'John Silva' })
112
112
  * ```
113
113
  */
114
- export declare const update: <T>(api: AxiosInstance, url: string, object: T) => Promise<T | ErrorMessage[]>;
114
+ export declare const update: <T>(api: ApiInstance, url: string, object: T) => Promise<T | ErrorMessage[]>;
115
115
  /**
116
116
  * Removes a specific record from the API via DELETE request
117
117
  *
118
118
  * @template T - Type of response
119
- * @param {AxiosInstance} api - Configured Axios instance with authentication
119
+ * @param {ApiInstance} api - Configured API instance with authentication
120
120
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
121
121
  * @param {string} id - ID of the record to be removed
122
122
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to response or array of errors
@@ -128,12 +128,12 @@ export declare const update: <T>(api: AxiosInstance, url: string, object: T) =>
128
128
  * const result = await remove(api, 'users', '123')
129
129
  * ```
130
130
  */
131
- export declare const remove: <T>(api: AxiosInstance, url: string, id: string) => Promise<ErrorMessage[] | T>;
131
+ export declare const remove: <T>(api: ApiInstance, url: string, id: string) => Promise<ErrorMessage[] | T>;
132
132
  /**
133
133
  * Removes a record with composite key (multiple identifiers) via DELETE request
134
134
  *
135
135
  * @template T - Type of response
136
- * @param {AxiosInstance} api - Configured Axios instance with authentication
136
+ * @param {ApiInstance} api - Configured API instance with authentication
137
137
  * @param {string} url - API endpoint path (without leading slash)
138
138
  * @param {Object} object - Object with additional data for deletion (if needed by backend)
139
139
  * @param {string} one - First identifier segment
@@ -150,7 +150,7 @@ export declare const remove: <T>(api: AxiosInstance, url: string, id: string) =>
150
150
  * const result = await removeComposite(api, 'user-roles', {}, 'user-123', 'role-admin', '', '')
151
151
  * ```
152
152
  */
153
- export declare const removeComposite: <T>(api: AxiosInstance, url: string, object: Object, one: string, two: string, three: string, four: string) => Promise<ErrorMessage[] | T>;
153
+ export declare const removeComposite: <T>(api: ApiInstance, url: string, object: Object, one: string, two: string, three: string, four: string) => Promise<ErrorMessage[] | T>;
154
154
  /**
155
155
  * Removes all records from a specific endpoint via DELETE request
156
156
  *
@@ -158,7 +158,7 @@ export declare const removeComposite: <T>(api: AxiosInstance, url: string, objec
158
158
  * Use with extreme caution and ensure this is the intended action.
159
159
  *
160
160
  * @template T - Type of response
161
- * @param {AxiosInstance} api - Configured Axios instance with authentication
161
+ * @param {ApiInstance} api - Configured API instance with authentication
162
162
  * @param {string} url - API endpoint path (without leading slash)
163
163
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to response or array of errors
164
164
  *
@@ -169,5 +169,5 @@ export declare const removeComposite: <T>(api: AxiosInstance, url: string, objec
169
169
  * const result = await removeAll(api, 'temp-data')
170
170
  * ```
171
171
  */
172
- export declare const removeAll: <T>(api: AxiosInstance, url: string) => Promise<ErrorMessage[] | T>;
172
+ export declare const removeAll: <T>(api: ApiInstance, url: string) => Promise<ErrorMessage[] | T>;
173
173
  //# sourceMappingURL=crud.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/services/crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AA+BxC;;;;;;;;;;;;;;;;GAgBG;AACH,eAA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AAe,GAAU,CAAC,EAAG,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,MAAM,gCAU7I,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,EAAG,KAAK,WAAW,EAAE,KAAK,MAAM,gCAIhE,CAAA"}
@@ -13,7 +13,7 @@ const api_1 = require("./api");
13
13
  /**
14
14
  * Processes API response errors and converts to standardized format
15
15
  *
16
- * @param {any} error - Axios error object from catch block
16
+ * @param {any} error - API error object from catch block
17
17
  * @returns {ErrorMessage[]} Array of formatted error messages with field and message properties
18
18
  *
19
19
  * @internal This is a utility function used internally by CRUD operations
@@ -35,7 +35,7 @@ const addError = (error) => {
35
35
  * Creates a new record in the API via POST request
36
36
  *
37
37
  * @template T - Type of object to be created
38
- * @param {AxiosInstance} api - Configured Axios instance with authentication
38
+ * @param {ApiInstance} api - Configured API instance with authentication
39
39
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
40
40
  * @param {T} object - Object data to be created
41
41
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to created data or array of errors
@@ -58,7 +58,7 @@ exports.create = create;
58
58
  * Creates multiple records at once in the API via batch POST request
59
59
  *
60
60
  * @template T - Type of objects to be created
61
- * @param {AxiosInstance} api - Configured Axios instance with authentication
61
+ * @param {ApiInstance} api - Configured API instance with authentication
62
62
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
63
63
  * @param {T[]} object - Array of objects to be created
64
64
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to created data or array of errors
@@ -95,7 +95,7 @@ exports.createAll = createAll;
95
95
  * - With sort: paginated and sorted search
96
96
  *
97
97
  * @template T - Type of individual items in the response
98
- * @param {AxiosInstance} api - Configured Axios instance with authentication
98
+ * @param {ApiInstance} api - Configured API instance with authentication
99
99
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
100
100
  * @param {Search} [search] - Optional search, pagination and sorting parameters
101
101
  * @param {number} [search.page] - Page number (zero-indexed)
@@ -146,7 +146,7 @@ exports.retrieve = retrieve;
146
146
  * Updates an existing record in the API via PUT request
147
147
  *
148
148
  * @template T - Type of object to be updated
149
- * @param {AxiosInstance} api - Configured Axios instance with authentication
149
+ * @param {ApiInstance} api - Configured API instance with authentication
150
150
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
151
151
  * @param {T} object - Updated object data (must include identifier)
152
152
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to response or array of errors
@@ -168,7 +168,7 @@ exports.update = update;
168
168
  * Removes a specific record from the API via DELETE request
169
169
  *
170
170
  * @template T - Type of response
171
- * @param {AxiosInstance} api - Configured Axios instance with authentication
171
+ * @param {ApiInstance} api - Configured API instance with authentication
172
172
  * @param {string} url - API endpoint path (without leading slash, e.g., 'users')
173
173
  * @param {string} id - ID of the record to be removed
174
174
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to response or array of errors
@@ -190,7 +190,7 @@ exports.remove = remove;
190
190
  * Removes a record with composite key (multiple identifiers) via DELETE request
191
191
  *
192
192
  * @template T - Type of response
193
- * @param {AxiosInstance} api - Configured Axios instance with authentication
193
+ * @param {ApiInstance} api - Configured API instance with authentication
194
194
  * @param {string} url - API endpoint path (without leading slash)
195
195
  * @param {Object} object - Object with additional data for deletion (if needed by backend)
196
196
  * @param {string} one - First identifier segment
@@ -227,7 +227,7 @@ exports.removeComposite = removeComposite;
227
227
  * Use with extreme caution and ensure this is the intended action.
228
228
  *
229
229
  * @template T - Type of response
230
- * @param {AxiosInstance} api - Configured Axios instance with authentication
230
+ * @param {ApiInstance} api - Configured API instance with authentication
231
231
  * @param {string} url - API endpoint path (without leading slash)
232
232
  * @returns {Promise<T | ErrorMessage[]>} Promise resolving to response or array of errors
233
233
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@forgepack/request",
3
- "version": "1.0.14",
4
- "description": "Opinionated Axios-based HTTP client for React applications with JWT support, interceptors, and API request standardization.",
3
+ "version": "1.1.1",
4
+ "description": "Opinionated Fetch-based HTTP client for React applications with JWT support, interceptors, and API request standardization.",
5
5
  "homepage": "https://forgepack.dev/packages/request",
6
6
  "bugs": {
7
7
  "url": "https://github.com/forgepack/request/issues"
@@ -13,7 +13,7 @@
13
13
  "type": "git",
14
14
  "url": "git+https://github.com/forgepack/request.git"
15
15
  },
16
- "license": "MIT License",
16
+ "license": "MIT",
17
17
  "keywords": [
18
18
  "react",
19
19
  "frontend",
@@ -66,6 +66,5 @@
66
66
  "typescript": "^5.9.3"
67
67
  },
68
68
  "dependencies": {
69
- "axios": "^1.13.2"
70
69
  }
71
70
  }