axiomate 1.0.2 → 1.0.3

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.

Potentially problematic release.


This version of axiomate might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axiomate",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Zero-boilerplate API client — define once, use everywhere.",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
package/src/_store.js CHANGED
@@ -1,9 +1,3 @@
1
- /**
2
- * _store.js
3
- * Internal shared state — library ke andar use hota hai
4
- * Developer directly use na kare
5
- */
6
-
7
1
  const _store = {
8
2
  instance: null,
9
3
  interceptors: {
package/src/createApi.js CHANGED
@@ -1,14 +1,11 @@
1
1
  const axios = require("axios");
2
2
  const { _store } = require("./_store");
3
3
 
4
- /**
5
- * Token getter — developer set karta hai apna logic
6
- */
7
4
  let _getToken = () => localStorage.getItem("token");
8
5
 
9
6
  /**
10
- * setTokenGetter — developer apna token logic provide kare
11
- * @param {Function} fn - function jo token return kare
7
+ * setTokenGetter — Developer provider there function to get token
8
+ * @param {Function} fn - function who return the token string
12
9
  *
13
10
  * @example
14
11
  * setTokenGetter(() => store.getState().auth.token);
@@ -21,13 +18,13 @@ const setTokenGetter = (fn) => {
21
18
  * createApi — library ka core function
22
19
  *
23
20
  * @param {Object} config
24
- * @param {string} config.baseUrl - Backend ka base URL
25
- * @param {Object} config.endpoints - Sare endpoints ka map
21
+ * @param {string} config.baseUrl - Backend base URL
22
+ * @param {Object} config.endpoints - All endpoints map
26
23
  * @param {Object} [config.headers] - Extra default headers
27
24
  * @param {number} [config.timeout] - Request timeout ms (default: 10000)
28
- * @param {boolean} [config.autoToken] - Auto Bearer token lagao (default: true)
25
+ * @param {boolean} [config.autoToken] - Auto Bearer token (default: true)
29
26
  *
30
- * @returns {Object} - Har endpoint ke liye ek callable function
27
+ * @returns {Object}
31
28
  *
32
29
  * @example
33
30
  * const api = createApi({
@@ -54,7 +51,7 @@ const createApi = (config) => {
54
51
  console.warn("[axiomate] No endpoints defined.");
55
52
  }
56
53
 
57
- // Axios instance banao
54
+ // Create Axios instance
58
55
  _store.instance = axios.create({
59
56
  baseURL: baseUrl,
60
57
  timeout,
@@ -75,7 +72,7 @@ const createApi = (config) => {
75
72
  }
76
73
  }
77
74
 
78
- // Developer ke custom request interceptors chalao
75
+
79
76
  let finalConfig = axiosConfig;
80
77
  for (const fn of _store.interceptors.request) {
81
78
  finalConfig = fn(finalConfig) || finalConfig;
@@ -96,12 +93,11 @@ const createApi = (config) => {
96
93
  return finalResponse;
97
94
  },
98
95
  (error) => {
99
- // Developer ke custom error interceptors chalao
96
+
100
97
  for (const fn of _store.interceptors.error) {
101
98
  fn(error);
102
99
  }
103
100
 
104
- // Meaningful error message banao
105
101
  const status = error?.response?.status;
106
102
  const message =
107
103
  error?.response?.data?.message ||
@@ -118,7 +114,7 @@ const createApi = (config) => {
118
114
  }
119
115
  );
120
116
 
121
- // ─── Endpoints ko functions mein convert karo ─────────────────────────────
117
+ // ─── Convert endpoints map to functions ─────────────────────────────────
122
118
  const api = {};
123
119
 
124
120
  for (const [name, endpoint] of Object.entries(endpoints)) {
@@ -132,9 +128,9 @@ const createApi = (config) => {
132
128
  /**
133
129
  * Generated endpoint function
134
130
  *
135
- * @param {Object} [data] - POST/PUT ke liye request body
136
- * @param {Object} [params] - GET ke liye query params
137
- * @param {Object} [extraConfig] - Axios extra config override
131
+ * @param {Object} [data]
132
+ * @param {Object} [params]
133
+ * @param {Object} [extraConfig]
138
134
  */
139
135
  api[name] = (data = {}, params = {}, extraConfig = {}) => {
140
136
  const upperMethod = method.toUpperCase();
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * interceptors.js
3
- * Developer apne custom interceptors register kare
3
+ * Developers can register their custom interceptors here
4
4
  */
5
5
 
6
6
  const { _store } = require("./_store");
7
7
 
8
8
  /**
9
9
  * addRequestInterceptor
10
- * Har request jaane se pehle ye function chalega
10
+ * This function runs before every request is sent
11
11
  *
12
12
  * @param {Function} fn - (axiosConfig) => axiosConfig
13
13
  *
@@ -23,7 +23,7 @@ const addRequestInterceptor = (fn) => {
23
23
 
24
24
  /**
25
25
  * addResponseInterceptor
26
- * Har successful response aane ke baad ye function chalega
26
+ * This function runs after every successful response is received
27
27
  *
28
28
  * @param {Function} fn - (response) => response
29
29
  *
@@ -39,7 +39,7 @@ const addResponseInterceptor = (fn) => {
39
39
 
40
40
  /**
41
41
  * addErrorInterceptor
42
- * Koi bhi request fail ho toh ye function chalega
42
+ * This function runs when any request fails
43
43
  *
44
44
  * @param {Function} fn - (error) => void
45
45
  *
package/src/useApi.js CHANGED
@@ -2,13 +2,13 @@ const { useState, useEffect, useCallback, useRef } = require("react");
2
2
 
3
3
  /**
4
4
  * useApi — React hook for API calls
5
- * Loading, error, data sab automatic!
5
+ * Loading, error, data states are all automatic!
6
6
  *
7
- * @param {Function} apiFn - api.getUser jaise function
7
+ * @param {Function} apiFn - api.getUser like function
8
8
  * @param {Object} [options]
9
- * @param {any} [options.params] - Function ko pass karne wale params
10
- * @param {boolean} [options.immediate] - Mount hote hi call karo (default: true)
11
- * @param {any} [options.initialData] - Data ka initial value
9
+ * @param {any} [options.params] - Parameters to pass to the function
10
+ * @param {boolean} [options.immediate] - Call immediately on mount (default: true)
11
+ * @param {any} [options.initialData] - Initial value for data
12
12
  *
13
13
  * @returns {{ data, loading, error, execute, reset }}
14
14
  *
@@ -34,7 +34,7 @@ const useApi = (apiFn, options = {}) => {
34
34
  const [loading, setLoading] = useState(immediate);
35
35
  const [error, setError] = useState(null);
36
36
 
37
- // Latest params ref — stale closure se bachne ke liye
37
+ // Latest params ref — to avoid stale closure
38
38
  const paramsRef = useRef(params);
39
39
  paramsRef.current = params;
40
40