@gajay/axios-refresh-core 1.4.0 โ†’ 1.5.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.
Files changed (2) hide show
  1. package/README.md +194 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # @gajay/axios-refresh-core
2
+
3
+ > Production-grade Axios refresh token engine with circuit breaker, cooldown lock, retry logic, cross-tab sync, anomaly detection, DevTools panel, and MCP support.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@gajay/axios-refresh-core.svg)](https://www.npmjs.com/package/@gajay/axios-refresh-core)
6
+ [![CI](https://github.com/GAjay/gajay-axios-refresher/actions/workflows/ci.yml/badge.svg)](https://github.com/GAjay/gajay-axios-refresher/actions)
7
+ [![MIT License](https://img.shields.io/npm/l/@gajay/axios-refresh-core.svg)](LICENSE)
8
+
9
+ ---
10
+
11
+ ## โœจ Features
12
+
13
+ - ๐Ÿ”„ Automatic Axios 401 refresh handling
14
+ - ๐Ÿง  Circuit breaker (OPEN / HALF_OPEN / CLOSED)
15
+ - โณ Cooldown lock to prevent refresh storms
16
+ - ๐Ÿ” Retry with configurable attempts
17
+ - ๐ŸŒ Cross-tab token sync (BroadcastChannel)
18
+ - ๐Ÿšจ Anomaly detection (excessive refresh detection)
19
+ - ๐Ÿ“Š DevTools floating debug panel
20
+ - ๐Ÿ” Optional logout fallback
21
+ - ๐Ÿงช Fully tested (Jest)
22
+ - โšก Tree-shakeable ESM + CJS build
23
+
24
+ ---
25
+
26
+ ## ๐Ÿ“ฆ Installation
27
+
28
+ ```bash
29
+ npm install @gajay/axios-refresh-core
30
+ ```
31
+
32
+ or
33
+
34
+ ```bash
35
+ yarn add @gajay/axios-refresh-core
36
+ ```
37
+
38
+ ---
39
+
40
+ ## ๐Ÿš€ Basic Usage
41
+
42
+ ```ts
43
+ import axios from "axios";
44
+ import { createAxiosRefresh } from "@gajay/axios-refresh-core";
45
+
46
+ const api = axios.create({
47
+ baseURL: "/api"
48
+ });
49
+
50
+ createAxiosRefresh({
51
+ axiosInstance: api,
52
+ refreshTokenFn: async () => {
53
+ const res = await axios.post("/auth/refresh");
54
+ return res.data.accessToken;
55
+ },
56
+ setAccessToken: (token) => {
57
+ api.defaults.headers.common.Authorization = `Bearer ${token}`;
58
+ }
59
+ });
60
+ ```
61
+
62
+ ---
63
+
64
+ ## ๐Ÿ›ก Circuit Breaker Example
65
+
66
+ ```ts
67
+ createAxiosRefresh({
68
+ axiosInstance: api,
69
+ refreshTokenFn,
70
+ circuitBreaker: {
71
+ enabled: true,
72
+ failureThreshold: 3,
73
+ timeoutMs: 10000
74
+ }
75
+ });
76
+ ```
77
+
78
+ ---
79
+
80
+ ## โณ Cooldown Lock Example
81
+
82
+ ```ts
83
+ createAxiosRefresh({
84
+ axiosInstance: api,
85
+ refreshTokenFn,
86
+ cooldown: {
87
+ enabled: true,
88
+ durationMs: 5000,
89
+ strategy: "reject" // or "wait"
90
+ }
91
+ });
92
+ ```
93
+
94
+ ---
95
+
96
+ ## ๐Ÿ” Retry Support
97
+
98
+ ```ts
99
+ createAxiosRefresh({
100
+ axiosInstance: api,
101
+ refreshTokenFn,
102
+ retry: {
103
+ enabled: true,
104
+ maxRetries: 2
105
+ }
106
+ });
107
+ ```
108
+
109
+ ---
110
+
111
+ ## ๐ŸŒ Cross-Tab Sync
112
+
113
+ Automatically syncs new access tokens across browser tabs using `BroadcastChannel`.
114
+
115
+ No additional setup required.
116
+
117
+ ---
118
+
119
+ ## ๐Ÿšจ Anomaly Detection
120
+
121
+ Detect excessive refresh attempts and optionally report to server.
122
+
123
+ ```ts
124
+ createAxiosRefresh({
125
+ axiosInstance: api,
126
+ refreshTokenFn,
127
+ anomaly: {
128
+ maxPerMinute: 5,
129
+ reportToServer: true,
130
+ reportEndpoint: "/security/anomaly"
131
+ }
132
+ });
133
+ ```
134
+
135
+ ---
136
+
137
+ ## ๐Ÿ“Š DevTools Panel
138
+
139
+ Enable floating debug panel (development only):
140
+
141
+ ```ts
142
+ createAxiosRefresh({
143
+ axiosInstance: api,
144
+ refreshTokenFn,
145
+ devtools: {
146
+ enabled: true
147
+ }
148
+ });
149
+ ```
150
+
151
+ ## ๐Ÿงช Testing
152
+
153
+ ```bash
154
+ npm run test
155
+ ```
156
+
157
+ ---
158
+
159
+ ## ๐Ÿ“ฆ Build
160
+
161
+ ```bash
162
+ npm run build
163
+ ```
164
+
165
+ ---
166
+
167
+ ## ๐Ÿ” Security Notes
168
+
169
+ - Always validate refresh token server-side
170
+ - Use short-lived access tokens
171
+ - Enable anomaly reporting in production
172
+ - Use HTTPS only
173
+
174
+ ---
175
+
176
+ ## ๐Ÿ“š Roadmap
177
+
178
+ - Chrome DevTools extension
179
+ - Metrics exporter
180
+ - WebSocket event streaming
181
+ - React DevTools integration
182
+ - SaaS monitoring dashboard
183
+
184
+ ---
185
+
186
+ ## ๐Ÿค Contributing
187
+
188
+ Pull requests welcome. Please use Conventional Commits.
189
+
190
+ ---
191
+
192
+ ## ๐Ÿ“„ License
193
+
194
+ MIT ยฉ Ajay Kumar Maheshwari
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gajay/axios-refresh-core",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Production-grade Axios refresh token engine with circuit breaker, cooldown, retry, cross-tab sync, anomaly detection and DevTools support.",
5
5
  "publishConfig": {
6
6
  "access": "public"