@navservice/core 1.56.0 → 1.57.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.
@@ -7,21 +7,25 @@ export default class api {
7
7
  private axios;
8
8
  private withAuth;
9
9
  constructor({ baseURL, withAuth }: ApiClientOptions);
10
- private set_bearer_token;
11
- get<T = any>({ url, params }: {
10
+ private get_headers;
11
+ get<T = any>({ url, params, setToken }: {
12
12
  url: string;
13
13
  params?: Record<string, any>;
14
+ setToken?: boolean;
14
15
  }): Promise<AxiosResponse<T>>;
15
- post<T = any>({ url, data }: {
16
+ post<T = any>({ url, data, setToken }: {
16
17
  url: string;
17
18
  data?: any;
19
+ setToken?: boolean;
18
20
  }): Promise<AxiosResponse<T>>;
19
- patch<T = any>({ url, data }: {
21
+ patch<T = any>({ url, data, setToken }: {
20
22
  url: string;
21
23
  data?: any;
24
+ setToken?: boolean;
22
25
  }): Promise<AxiosResponse<T>>;
23
- delete<T = any>({ url }: {
26
+ delete<T = any>({ url, setToken }: {
24
27
  url: string;
28
+ setToken?: boolean;
25
29
  }): Promise<AxiosResponse<T>>;
26
30
  }
27
31
  export {};
package/build/es/utils.js CHANGED
@@ -62,30 +62,37 @@ class api {
62
62
  "Content-Type": "application/json"
63
63
  }
64
64
  });
65
- this.set_bearer_token();
66
65
  }
67
- set_bearer_token() {
68
- this.axios.interceptors.request.use((config)=>{
69
- if (this.withAuth) {
70
- const auth = utils_session_storage.get_item_session_storage("auth_user");
71
- if (auth?.data?.usuario?.token) config.headers.Authorization = `Bearer ${auth.data.usuario.token}`;
66
+ get_headers(setToken) {
67
+ if (true === setToken && true === this.withAuth) {
68
+ const auth = utils_session_storage.get_item_session_storage("auth_user");
69
+ return {
70
+ headers: {
71
+ Authorization: auth?.data?.usuario?.token ? `Bearer ${auth.data.usuario.token}` : void 0,
72
+ "Content-Type": "application/json"
73
+ }
74
+ };
75
+ }
76
+ return {
77
+ headers: {
78
+ "Content-Type": "application/json"
72
79
  }
73
- return config;
74
- });
80
+ };
75
81
  }
76
- async get({ url, params }) {
82
+ async get({ url, params, setToken = true }) {
77
83
  return this.axios.get(url, {
78
- params
84
+ params,
85
+ ...this.get_headers(setToken)
79
86
  });
80
87
  }
81
- async post({ url, data }) {
82
- return this.axios.post(url, data);
88
+ async post({ url, data, setToken = true }) {
89
+ return this.axios.post(url, data, this.get_headers(setToken));
83
90
  }
84
- async patch({ url, data }) {
85
- return this.axios.patch(url, data);
91
+ async patch({ url, data, setToken = true }) {
92
+ return this.axios.patch(url, data, this.get_headers(setToken));
86
93
  }
87
- async delete({ url }) {
88
- return this.axios.delete(url);
94
+ async delete({ url, setToken = true }) {
95
+ return this.axios.delete(url, this.get_headers(setToken));
89
96
  }
90
97
  }
91
98
  const _data = class {
@@ -7,21 +7,25 @@ export default class api {
7
7
  private axios;
8
8
  private withAuth;
9
9
  constructor({ baseURL, withAuth }: ApiClientOptions);
10
- private set_bearer_token;
11
- get<T = any>({ url, params }: {
10
+ private get_headers;
11
+ get<T = any>({ url, params, setToken }: {
12
12
  url: string;
13
13
  params?: Record<string, any>;
14
+ setToken?: boolean;
14
15
  }): Promise<AxiosResponse<T>>;
15
- post<T = any>({ url, data }: {
16
+ post<T = any>({ url, data, setToken }: {
16
17
  url: string;
17
18
  data?: any;
19
+ setToken?: boolean;
18
20
  }): Promise<AxiosResponse<T>>;
19
- patch<T = any>({ url, data }: {
21
+ patch<T = any>({ url, data, setToken }: {
20
22
  url: string;
21
23
  data?: any;
24
+ setToken?: boolean;
22
25
  }): Promise<AxiosResponse<T>>;
23
- delete<T = any>({ url }: {
26
+ delete<T = any>({ url, setToken }: {
24
27
  url: string;
28
+ setToken?: boolean;
25
29
  }): Promise<AxiosResponse<T>>;
26
30
  }
27
31
  export {};
@@ -127,32 +127,37 @@ class api {
127
127
  "Content-Type": "application/json"
128
128
  }
129
129
  });
130
- this.set_bearer_token();
131
- }
132
- set_bearer_token() {
133
- this.axios.interceptors.request.use((config)=>{
134
- if (this.withAuth) {
135
- const auth = utils_session_storage.get_item_session_storage("auth_user");
136
- if (auth?.data?.usuario?.token) {
137
- config.headers.Authorization = `Bearer ${auth.data.usuario.token}`;
130
+ }
131
+ get_headers(setToken) {
132
+ if (setToken === true && this.withAuth === true) {
133
+ const auth = utils_session_storage.get_item_session_storage("auth_user");
134
+ return {
135
+ headers: {
136
+ Authorization: auth?.data?.usuario?.token ? `Bearer ${auth.data.usuario.token}` : undefined,
137
+ "Content-Type": "application/json"
138
138
  }
139
+ };
140
+ }
141
+ return {
142
+ headers: {
143
+ "Content-Type": "application/json"
139
144
  }
140
- return config;
141
- });
145
+ };
142
146
  }
143
- async get({ url, params }) {
147
+ async get({ url, params, setToken = true }) {
144
148
  return this.axios.get(url, {
145
- params
149
+ params,
150
+ ...this.get_headers(setToken)
146
151
  });
147
152
  }
148
- async post({ url, data }) {
149
- return this.axios.post(url, data);
153
+ async post({ url, data, setToken = true }) {
154
+ return this.axios.post(url, data, this.get_headers(setToken));
150
155
  }
151
- async patch({ url, data }) {
152
- return this.axios.patch(url, data);
156
+ async patch({ url, data, setToken = true }) {
157
+ return this.axios.patch(url, data, this.get_headers(setToken));
153
158
  }
154
- async delete({ url }) {
155
- return this.axios.delete(url);
159
+ async delete({ url, setToken = true }) {
160
+ return this.axios.delete(url, this.get_headers(setToken));
156
161
  }
157
162
  }
158
163
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.56.0",
3
+ "version": "1.57.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {