@sabuj0338/axios-friday 0.1.4 → 1.0.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 +45 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -15,9 +15,9 @@ npm install @sabuj0338/axios-friday
15
15
  ## Usage
16
16
 
17
17
  ```python
18
- import Friday from '@sabuj0338/axios-friday'
18
+ import { Friday } from "@sabuj0338/axios-friday";
19
19
 
20
- # Example, Configure first
20
+ # Configure and use
21
21
 
22
22
  const baseURL = "https://sabuj0338.github.io/portfolio";
23
23
 
@@ -30,6 +30,49 @@ const friday = new Friday({
30
30
  # enableAccessToken: true,
31
31
  });
32
32
 
33
+ # returns 'AxiosResponse'
34
+ const response = await friday.get(new URL(baseURL));
35
+
36
+ ```
37
+
38
+ ## Example of using a class that Extends `Friday`
39
+
40
+ ```python
41
+ import { Friday } from "@sabuj0338/axios-friday";
42
+ import { AxiosResponse } from "axios";
43
+ import Cookies from "js-cookie";
44
+ import toast from "react-hot-toast";
45
+
46
+ const BASE_API_URL = import.meta.env.VITE_BASE_API_URL;
47
+ const REFRESH_TOKEN_API = import.meta.env.VITE_REFRESH_TOKEN_API;
48
+ const REFRESH_TOKEN_KEY = import.meta.env.VITE_REFRESH_TOKEN_KEY;
49
+ const ACCESS_TOKEN_KEY = import.meta.env.VITE_ACCESS_TOKEN_KEY;
50
+
51
+ class MyFriday extends Friday {
52
+ constructor(baseURL: string = BASE_API_URL) {
53
+ super({
54
+ baseURL: baseURL,
55
+ refreshTokenEndpoint: REFRESH_TOKEN_API,
56
+ accessTokenKey: ACCESS_TOKEN_KEY,
57
+ refreshTokenKey: REFRESH_TOKEN_KEY,
58
+ enableRefreshToken: true,
59
+ enableAccessToken: true,
60
+ });
61
+ }
62
+
63
+ override resetTokens(res: AxiosResponse<any, any>) {
64
+ Cookies.set(ACCESS_TOKEN_KEY, res.data.tokens.access.token);
65
+ Cookies.set(REFRESH_TOKEN_KEY, res.data.tokens.refresh.token);
66
+ }
67
+
68
+ override throwError(message: string): void {
69
+ toast.error(message);
70
+ }
71
+ }
72
+
73
+ export const friday = new MyFriday();
74
+
75
+
33
76
  # returns 'AxiosResponse'
34
77
  const response = await friday.get(new URL(baseURL));
35
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sabuj0338/axios-friday",
3
- "version": "0.1.4",
3
+ "version": "1.0.0",
4
4
  "description": "Friday - a axios based api handling custom class. which has refresh token mechanism configured.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",