@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.
@@ -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 };
@@ -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.5",
3
+ "version": "1.0.6",
4
4
  "private": false,
5
- "main": "src/index.ts",
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.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 -p ../../tsconfig.base.json",
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
  }
@@ -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
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Target: es2023
9
- ESM Build start
10
- CJS Build start
11
- CJS dist/index.js 3.76 KB
12
- CJS ⚡️ Build success in 57ms
13
- ESM dist/index.mjs 1.82 KB
14
- ESM ⚡️ 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
- });
@@ -1,10 +0,0 @@
1
- import axios, { AxiosInstance } from 'axios';
2
-
3
- export function createHttpClient(baseURL: string): AxiosInstance {
4
- return axios.create({
5
- baseURL,
6
- headers: {
7
- 'Content-Type': 'application/json',
8
- },
9
- });
10
- }
@@ -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
- }
@@ -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
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- }