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