@justins-home/http-client 1.0.4 → 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/dist/index.js CHANGED
@@ -42,9 +42,9 @@ module.exports = __toCommonJS(index_exports);
42
42
 
43
43
  // src/clients/publicClient.ts
44
44
  var import_axios = __toESM(require("axios"));
45
- var baseURL = process.env.NEXT_PUBLIC_API_URL;
45
+ var baseURL = process.env.API_URL;
46
46
  if (!baseURL) {
47
- throw new Error("NEXT_PUBLIC_API_URL is not defined");
47
+ throw new Error("API_URL is not defined");
48
48
  }
49
49
  var publicClient = import_axios.default.create({
50
50
  baseURL,
@@ -55,9 +55,9 @@ var publicClient = import_axios.default.create({
55
55
 
56
56
  // src/clients/authClient.ts
57
57
  var import_axios2 = __toESM(require("axios"));
58
- var baseURL2 = process.env.NEXT_PUBLIC_API_URL;
58
+ var baseURL2 = process.env.API_URL;
59
59
  if (!baseURL2) {
60
- throw new Error("NEXT_PUBLIC_API_URL is not defined");
60
+ throw new Error("API_URL is not defined");
61
61
  }
62
62
  var authClient = import_axios2.default.create({
63
63
  baseURL: baseURL2,
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  // src/clients/publicClient.ts
2
2
  import axios from "axios";
3
- var baseURL = process.env.NEXT_PUBLIC_API_URL;
3
+ var baseURL = process.env.API_URL;
4
4
  if (!baseURL) {
5
- throw new Error("NEXT_PUBLIC_API_URL is not defined");
5
+ throw new Error("API_URL is not defined");
6
6
  }
7
7
  var publicClient = axios.create({
8
8
  baseURL,
@@ -13,9 +13,9 @@ var publicClient = axios.create({
13
13
 
14
14
  // src/clients/authClient.ts
15
15
  import axios2 from "axios";
16
- var baseURL2 = process.env.NEXT_PUBLIC_API_URL;
16
+ var baseURL2 = process.env.API_URL;
17
17
  if (!baseURL2) {
18
- throw new Error("NEXT_PUBLIC_API_URL is not defined");
18
+ throw new Error("API_URL is not defined");
19
19
  }
20
20
  var authClient = axios2.create({
21
21
  baseURL: baseURL2,
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "@justins-home/http-client",
3
- "version": "1.0.4",
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.4 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
- ESM dist/index.mjs 1.87 KB
12
- ESM ⚡️ Build success in 40ms
13
- CJS dist/index.js 3.81 KB
14
- CJS ⚡️ Build success in 41ms
package/CHANGELOG.md DELETED
@@ -1,52 +0,0 @@
1
- # @justins-home/http-client
2
-
3
- ## 1.0.4
4
-
5
- ### Patch Changes
6
-
7
- - fix validated script
8
-
9
- ## 1.0.3
10
-
11
- ### Patch Changes
12
-
13
- - created a setup auth handler for handling token
14
-
15
- ## 1.0.2
16
-
17
- ### Patch Changes
18
-
19
- - added more typing to TS scribe doc
20
-
21
- ## 1.0.1
22
-
23
- ### Patch Changes
24
-
25
- - added ApiError to normalizeError
26
-
27
- ## 1.0.0
28
-
29
- ### Major Changes
30
-
31
- - 26690e2: release initial packages
32
-
33
- ### Minor Changes
34
-
35
- - aced108: added minor pumb
36
-
37
- ### Patch Changes
38
-
39
- - Updated dependencies [aced108]
40
- - Updated dependencies [26690e2]
41
- - @justins-home/types@1.0.0
42
-
43
- ## 0.1.0
44
-
45
- ### Minor Changes
46
-
47
- - 3f39ece: first release
48
-
49
- ### Patch Changes
50
-
51
- - Updated dependencies [3f39ece]
52
- - @justins-home/types@0.0.2
@@ -1,14 +0,0 @@
1
- import axios from 'axios';
2
-
3
- const baseURL = process.env.NEXT_PUBLIC_API_URL;
4
-
5
- if (!baseURL) {
6
- throw new Error('NEXT_PUBLIC_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.NEXT_PUBLIC_API_URL;
4
-
5
- if (!baseURL) {
6
- throw new Error('NEXT_PUBLIC_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
- }