@justins-home/http-client 1.0.5 → 1.0.6
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.
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/package.json +10 -5
- package/.turbo/turbo-build.log +0 -14
- package/CHANGELOG.md +0 -58
- package/src/clients/authClient.ts +0 -14
- package/src/clients/publicClient.ts +0 -14
- package/src/createHttpClient.ts +0 -10
- package/src/helpers/initClient.ts +0 -11
- package/src/helpers/request.ts +0 -13
- package/src/index.ts +0 -10
- package/src/interceptors/auth.interceptor.ts +0 -14
- package/src/interceptors/error.interceptor.ts +0 -14
- package/tsconfig.json +0 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as axios from 'axios';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
|
|
4
|
+
declare const publicClient: axios.AxiosInstance;
|
|
5
|
+
|
|
6
|
+
declare const authClient: axios.AxiosInstance;
|
|
7
|
+
|
|
8
|
+
declare function request<T>(client: AxiosInstance, promise: Promise<any>): Promise<T>;
|
|
9
|
+
|
|
10
|
+
declare function initApiToken(options: {
|
|
11
|
+
getToken: () => string | null;
|
|
12
|
+
}): void;
|
|
13
|
+
|
|
14
|
+
declare function createHttpClient(baseURL: string): AxiosInstance;
|
|
15
|
+
|
|
16
|
+
declare function registerAuthInterceptor(getToken: () => string | null): void;
|
|
17
|
+
|
|
18
|
+
declare function registerErrorInterceptor(client: any): void;
|
|
19
|
+
|
|
20
|
+
export { authClient, createHttpClient, initApiToken, publicClient, registerAuthInterceptor, registerErrorInterceptor, request };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as axios from 'axios';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
|
|
4
|
+
declare const publicClient: axios.AxiosInstance;
|
|
5
|
+
|
|
6
|
+
declare const authClient: axios.AxiosInstance;
|
|
7
|
+
|
|
8
|
+
declare function request<T>(client: AxiosInstance, promise: Promise<any>): Promise<T>;
|
|
9
|
+
|
|
10
|
+
declare function initApiToken(options: {
|
|
11
|
+
getToken: () => string | null;
|
|
12
|
+
}): void;
|
|
13
|
+
|
|
14
|
+
declare function createHttpClient(baseURL: string): AxiosInstance;
|
|
15
|
+
|
|
16
|
+
declare function registerAuthInterceptor(getToken: () => string | null): void;
|
|
17
|
+
|
|
18
|
+
declare function registerErrorInterceptor(client: any): void;
|
|
19
|
+
|
|
20
|
+
export { authClient, createHttpClient, initApiToken, publicClient, registerAuthInterceptor, registerErrorInterceptor, request };
|
package/package.json
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justins-home/http-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"private": false,
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
6
11
|
"dependencies": {
|
|
7
12
|
"axios": "^1.13.6",
|
|
8
|
-
"@justins-home/types": "1.0.
|
|
13
|
+
"@justins-home/types": "1.0.1"
|
|
9
14
|
},
|
|
10
15
|
"publishConfig": {
|
|
11
16
|
"access": "public"
|
|
12
17
|
},
|
|
13
18
|
"scripts": {
|
|
14
19
|
"lint": "eslint src",
|
|
15
|
-
"check-types": "tsc --noEmit
|
|
16
|
-
"build": "tsup src/index.ts --format esm,cjs",
|
|
20
|
+
"check-types": "tsc --noEmit",
|
|
21
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --tsconfig tsconfig.json",
|
|
17
22
|
"test": "vitest"
|
|
18
23
|
}
|
|
19
24
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @justins-home/http-client@1.0.5 build /home/runner/work/justins-home-platform-ui/justins-home-platform-ui/packages/http-client
|
|
3
|
-
> tsup src/index.ts --format esm,cjs
|
|
4
|
-
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.5.1
|
|
8
|
-
[34mCLI[39m Target: es2023
|
|
9
|
-
[34mESM[39m Build start
|
|
10
|
-
[34mCJS[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[32m3.76 KB[39m
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in 57ms
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m1.82 KB[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in 58ms
|
package/CHANGELOG.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# @justins-home/http-client
|
|
2
|
-
|
|
3
|
-
## 1.0.5
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- updated env variable name
|
|
8
|
-
|
|
9
|
-
## 1.0.4
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- fix validated script
|
|
14
|
-
|
|
15
|
-
## 1.0.3
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- created a setup auth handler for handling token
|
|
20
|
-
|
|
21
|
-
## 1.0.2
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- added more typing to TS scribe doc
|
|
26
|
-
|
|
27
|
-
## 1.0.1
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- added ApiError to normalizeError
|
|
32
|
-
|
|
33
|
-
## 1.0.0
|
|
34
|
-
|
|
35
|
-
### Major Changes
|
|
36
|
-
|
|
37
|
-
- 26690e2: release initial packages
|
|
38
|
-
|
|
39
|
-
### Minor Changes
|
|
40
|
-
|
|
41
|
-
- aced108: added minor pumb
|
|
42
|
-
|
|
43
|
-
### Patch Changes
|
|
44
|
-
|
|
45
|
-
- Updated dependencies [aced108]
|
|
46
|
-
- Updated dependencies [26690e2]
|
|
47
|
-
- @justins-home/types@1.0.0
|
|
48
|
-
|
|
49
|
-
## 0.1.0
|
|
50
|
-
|
|
51
|
-
### Minor Changes
|
|
52
|
-
|
|
53
|
-
- 3f39ece: first release
|
|
54
|
-
|
|
55
|
-
### Patch Changes
|
|
56
|
-
|
|
57
|
-
- Updated dependencies [3f39ece]
|
|
58
|
-
- @justins-home/types@0.0.2
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const baseURL = process.env.API_URL;
|
|
4
|
-
|
|
5
|
-
if (!baseURL) {
|
|
6
|
-
throw new Error('API_URL is not defined');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const authClient = axios.create({
|
|
10
|
-
baseURL,
|
|
11
|
-
headers: {
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
},
|
|
14
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const baseURL = process.env.API_URL;
|
|
4
|
-
|
|
5
|
-
if (!baseURL) {
|
|
6
|
-
throw new Error('API_URL is not defined');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const publicClient = axios.create({
|
|
10
|
-
baseURL,
|
|
11
|
-
headers: {
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
},
|
|
14
|
-
});
|
package/src/createHttpClient.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { registerAuthInterceptor } from '../interceptors/auth.interceptor';
|
|
2
|
-
|
|
3
|
-
let initialized = false;
|
|
4
|
-
|
|
5
|
-
export function initApiToken(options: { getToken: () => string | null }) {
|
|
6
|
-
if (initialized) return;
|
|
7
|
-
|
|
8
|
-
registerAuthInterceptor(options.getToken);
|
|
9
|
-
|
|
10
|
-
initialized = true;
|
|
11
|
-
}
|
package/src/helpers/request.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { ApiResponse } from '@justins-home/types';
|
|
3
|
-
|
|
4
|
-
export async function request<T>(
|
|
5
|
-
client: AxiosInstance,
|
|
6
|
-
promise: Promise<any>,
|
|
7
|
-
): Promise<T> {
|
|
8
|
-
const response = await promise;
|
|
9
|
-
|
|
10
|
-
const payload = response.data as ApiResponse<T>;
|
|
11
|
-
|
|
12
|
-
return payload.data as T;
|
|
13
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './clients/publicClient';
|
|
2
|
-
export * from './clients/authClient';
|
|
3
|
-
|
|
4
|
-
export * from './helpers/request';
|
|
5
|
-
export * from './helpers/initClient';
|
|
6
|
-
|
|
7
|
-
export * from './createHttpClient';
|
|
8
|
-
|
|
9
|
-
export * from './interceptors/auth.interceptor';
|
|
10
|
-
export * from './interceptors/error.interceptor';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { authClient } from '../clients/authClient';
|
|
2
|
-
|
|
3
|
-
export function registerAuthInterceptor(getToken: () => string | null) {
|
|
4
|
-
authClient.interceptors.request.use((config) => {
|
|
5
|
-
const token = getToken();
|
|
6
|
-
|
|
7
|
-
if (token) {
|
|
8
|
-
config.headers = config.headers ?? {};
|
|
9
|
-
config.headers.Authorization = `Bearer ${token}`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return config;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AxiosError } from 'axios';
|
|
2
|
-
|
|
3
|
-
export function registerErrorInterceptor(client: any) {
|
|
4
|
-
client.interceptors.response.use(
|
|
5
|
-
(response: any) => response,
|
|
6
|
-
(error: AxiosError) => {
|
|
7
|
-
if (error.response?.status === 401) {
|
|
8
|
-
console.warn('Unauthorized request');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return Promise.reject(error);
|
|
12
|
-
},
|
|
13
|
-
);
|
|
14
|
-
}
|
package/tsconfig.json
DELETED