@justins-home/http-client 1.0.1 → 1.0.3

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.
@@ -1,6 +1,5 @@
1
-  WARN  Issue while reading "/home/runner/work/justins-home-platform-ui/justins-home-platform-ui/.npmrc". Failed to replace env in config: ${NODE_AUTH_TOKEN}
2
1
 
3
- > @justins-home/http-client@1.0.1 build /home/runner/work/justins-home-platform-ui/justins-home-platform-ui/packages/http-client
2
+ > @justins-home/http-client@1.0.3 build /home/runner/work/justins-home-platform-ui/justins-home-platform-ui/packages/http-client
4
3
  > tsup src/index.ts --format esm,cjs
5
4
 
6
5
  CLI Building entry: src/index.ts
@@ -9,7 +8,7 @@
9
8
  CLI Target: es2023
10
9
  ESM Build start
11
10
  CJS Build start
12
- CJS dist/index.js 3.58 KB
13
- CJS ⚡️ Build success in 64ms
14
- ESM dist/index.mjs 1.67 KB
15
- ESM ⚡️ Build success in 64ms
11
+ CJS dist/index.js 3.81 KB
12
+ CJS ⚡️ Build success in 75ms
13
+ ESM dist/index.mjs 1.87 KB
14
+ ESM ⚡️ Build success in 76ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @justins-home/http-client
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - created a setup auth handler for handling token
8
+
9
+ ## 1.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - added more typing to TS scribe doc
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  authClient: () => authClient,
34
34
  createHttpClient: () => createHttpClient,
35
+ initApiToken: () => initApiToken,
35
36
  publicClient: () => publicClient,
36
37
  registerAuthInterceptor: () => registerAuthInterceptor,
37
38
  registerErrorInterceptor: () => registerErrorInterceptor,
@@ -72,17 +73,6 @@ async function request(client, promise) {
72
73
  return payload.data;
73
74
  }
74
75
 
75
- // src/createHttpClient.ts
76
- var import_axios3 = __toESM(require("axios"));
77
- function createHttpClient(baseURL3) {
78
- return import_axios3.default.create({
79
- baseURL: baseURL3,
80
- headers: {
81
- "Content-Type": "application/json"
82
- }
83
- });
84
- }
85
-
86
76
  // src/interceptors/auth.interceptor.ts
87
77
  function registerAuthInterceptor(getToken) {
88
78
  authClient.interceptors.request.use((config) => {
@@ -95,6 +85,25 @@ function registerAuthInterceptor(getToken) {
95
85
  });
96
86
  }
97
87
 
88
+ // src/helpers/initClient.ts
89
+ var initialized = false;
90
+ function initApiToken(options) {
91
+ if (initialized) return;
92
+ registerAuthInterceptor(options.getToken);
93
+ initialized = true;
94
+ }
95
+
96
+ // src/createHttpClient.ts
97
+ var import_axios3 = __toESM(require("axios"));
98
+ function createHttpClient(baseURL3) {
99
+ return import_axios3.default.create({
100
+ baseURL: baseURL3,
101
+ headers: {
102
+ "Content-Type": "application/json"
103
+ }
104
+ });
105
+ }
106
+
98
107
  // src/interceptors/error.interceptor.ts
99
108
  function registerErrorInterceptor(client) {
100
109
  client.interceptors.response.use(
@@ -111,6 +120,7 @@ function registerErrorInterceptor(client) {
111
120
  0 && (module.exports = {
112
121
  authClient,
113
122
  createHttpClient,
123
+ initApiToken,
114
124
  publicClient,
115
125
  registerAuthInterceptor,
116
126
  registerErrorInterceptor,
package/dist/index.mjs CHANGED
@@ -31,17 +31,6 @@ async function request(client, promise) {
31
31
  return payload.data;
32
32
  }
33
33
 
34
- // src/createHttpClient.ts
35
- import axios3 from "axios";
36
- function createHttpClient(baseURL3) {
37
- return axios3.create({
38
- baseURL: baseURL3,
39
- headers: {
40
- "Content-Type": "application/json"
41
- }
42
- });
43
- }
44
-
45
34
  // src/interceptors/auth.interceptor.ts
46
35
  function registerAuthInterceptor(getToken) {
47
36
  authClient.interceptors.request.use((config) => {
@@ -54,6 +43,25 @@ function registerAuthInterceptor(getToken) {
54
43
  });
55
44
  }
56
45
 
46
+ // src/helpers/initClient.ts
47
+ var initialized = false;
48
+ function initApiToken(options) {
49
+ if (initialized) return;
50
+ registerAuthInterceptor(options.getToken);
51
+ initialized = true;
52
+ }
53
+
54
+ // src/createHttpClient.ts
55
+ import axios3 from "axios";
56
+ function createHttpClient(baseURL3) {
57
+ return axios3.create({
58
+ baseURL: baseURL3,
59
+ headers: {
60
+ "Content-Type": "application/json"
61
+ }
62
+ });
63
+ }
64
+
57
65
  // src/interceptors/error.interceptor.ts
58
66
  function registerErrorInterceptor(client) {
59
67
  client.interceptors.response.use(
@@ -69,6 +77,7 @@ function registerErrorInterceptor(client) {
69
77
  export {
70
78
  authClient,
71
79
  createHttpClient,
80
+ initApiToken,
72
81
  publicClient,
73
82
  registerAuthInterceptor,
74
83
  registerErrorInterceptor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justins-home/http-client",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "main": "src/index.ts",
6
6
  "dependencies": {
@@ -0,0 +1,11 @@
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/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './clients/publicClient';
2
2
  export * from './clients/authClient';
3
3
 
4
4
  export * from './helpers/request';
5
+ export * from './helpers/initClient';
5
6
 
6
7
  export * from './createHttpClient';
7
8