@jaseeey/request-manager 2.1.0 → 2.1.2

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.
Files changed (2) hide show
  1. package/README.md +41 -19
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -14,7 +14,7 @@ Should you wish to extend the behaviour, or modify it for your own purposes, the
14
14
 
15
15
  ## Features
16
16
 
17
- - Prevents duplicate simultaneous requests to the same URL and method.
17
+ - Prevents duplicate simultaneous requests to the same client instance, URL, and method.
18
18
  - Supports TypeScript for improved type safety and developer experience.
19
19
  - Allows for optional onSuccess and onError callbacks to handle responses.
20
20
  - Generates both CommonJS (CJS) and ECMAScript Module (ESM) distributions for broad compatibility.
@@ -31,43 +31,63 @@ npm install @jaseeey/request-manager
31
31
 
32
32
  Here's a basic example of how to use the RequestManager library:
33
33
 
34
- ### With Callbacks
34
+ ### Recommended: Default Instance
35
35
 
36
36
  ```javascript
37
- import { RequestManager } from '@jaseeey/request-manager';
37
+ import requestManager from '@jaseeey/request-manager';
38
38
 
39
39
  const client = axios.create();
40
40
  const url = 'https://example.com';
41
41
  const method = 'GET';
42
42
 
43
- RequestManager.call(client, method, url, null, null, res => {
44
- // Handle your response here, any processing will only be run once.
45
- }, err => {
46
- // Handle your error here
47
- });
43
+ const response = await requestManager.call(client, method, url);
48
44
  ```
49
45
 
50
- ### Without Callbacks
46
+ ### With Callbacks and Transforming Success Result
51
47
 
52
48
  ```javascript
53
- import { RequestManager } from '@jaseeey/request-manager';
49
+ import requestManager from '@jaseeey/request-manager';
54
50
 
55
51
  const client = axios.create();
56
52
  const url = 'https://example.com';
57
- const method = 'GET';
58
53
 
59
- try {
60
- const response = await RequestManager.call(client, method, url);
61
- // Handle your response here, any processing will be run multiple times upon multiple requests.
62
- }
63
- catch (err) {
64
- // Handle your error here
65
- }
54
+ const result = await requestManager.call(
55
+ client,
56
+ 'GET',
57
+ url,
58
+ {},
59
+ {},
60
+ res => res.data, // Returning a value changes the resolved result
61
+ err => {
62
+ // Handle your error here
63
+ }
64
+ );
66
65
  ```
67
66
 
67
+ ### Creating Isolated Managers
68
+
69
+ ```javascript
70
+ import { RequestManager } from '@jaseeey/request-manager';
71
+
72
+ const client = axios.create();
73
+ const scopedRequestManager = new RequestManager();
74
+
75
+ const response = await scopedRequestManager.call(client, 'GET', 'https://example.com');
76
+ ```
77
+
78
+ ### Legacy Static API (Backward Compatibility)
79
+
80
+ ```javascript
81
+ import { RequestManager } from '@jaseeey/request-manager';
82
+
83
+ const response = await RequestManager.call(client, 'GET', 'https://example.com');
84
+ ```
85
+
86
+ `RequestManager.call(...)` is supported for backward compatibility, but the default instance API is recommended.
87
+
68
88
  ## API Reference
69
89
 
70
- ### `call(client, method, url, data, config, onSuccess, onError)`
90
+ ### `requestManager.call(client, method, url, data, config, onSuccess, onError)`
71
91
 
72
92
  - `client`: The HTTP client instance used for making requests.
73
93
  - `method`: The HTTP method (e.g., 'GET', 'POST').
@@ -77,6 +97,8 @@ catch (err) {
77
97
  - `onSuccess` (optional): A callback function that is called when the request is successful. Returning a non-`undefined` value from this callback changes the resolved value of the `call()` promise.
78
98
  - `onError` (optional): A callback function that is called when the request fails.
79
99
 
100
+ `RequestManager.call(...)` is also available as a static compatibility API and delegates to the shared default instance.
101
+
80
102
  ## Known Limitations
81
103
 
82
104
  ### Unified Callback Execution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaseeey/request-manager",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "A library to prevent multiple API requests when called simultaneously",
5
5
  "license": "MIT",
6
6
  "author": "Jason Ilicic <me@jasey.io>",
@@ -24,13 +24,13 @@
24
24
  "test": "vitest run --coverage"
25
25
  },
26
26
  "dependencies": {
27
- "axios": "^1.13.6"
27
+ "axios": "^1.15.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@vitest/coverage-v8": "^4.0.18",
30
+ "@vitest/coverage-v8": "^4.1.4",
31
31
  "braces": "^3.0.3",
32
32
  "typescript": "^5.9.3",
33
- "vitest": "^4.0.18"
33
+ "vitest": "^4.1.4"
34
34
  },
35
35
  "main": "./dist/cjs/index.js",
36
36
  "module": "./dist/esm/index.js",