@navservice/core 1.77.0 → 1.79.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.
package/build/es/index.js CHANGED
@@ -150,62 +150,38 @@ const _session_storage = class {
150
150
  }
151
151
  };
152
152
  const utils_session_storage = _session_storage;
153
- const _environment = class {
154
- static set(props) {
155
- window.sessionStorage.setItem("ENVIRONMENT", props);
156
- }
157
- static get get() {
158
- return window.sessionStorage.getItem("ENVIRONMENT");
159
- }
160
- };
161
- const utils_environment = _environment;
162
153
  const _api_api = class _api {
163
154
  static servidor_pricipal = class {
164
- static get #axios() {
155
+ static axios(key) {
156
+ const baseURL = sessionStorage.getItem(key);
157
+ if (!baseURL) throw new Error("API não inicializada no service core");
165
158
  return axios.create({
166
- baseURL: this.resolve_base_url()
159
+ baseURL
167
160
  });
168
161
  }
169
- static resolve_base_url() {
170
- try {
171
- if ("undefined" == typeof window) throw new Error("resolveApiBaseURL must run in browser");
172
- const { origin, hostname } = window.location;
173
- if (hostname.includes("navsoftware")) {
174
- const apiOrigin = origin.replace(/^https?:\/\/app/, (match)=>match.replace("app", "api"));
175
- return apiOrigin;
176
- }
177
- const apiOverride = utils_environment.get;
178
- if ("SANDBOX" === apiOverride) return "https://api-sandbox.navsoftware.com.br";
179
- if ("PRODUCAO" === apiOverride) return "https://api.navsoftware.com.br";
180
- if ("LOCALHOST" === apiOverride) return "http://localhost:8787";
181
- if ("localhost" === hostname || hostname.startsWith("localhost")) return "http://localhost:8787";
182
- } catch (error) {
183
- throw new Error(`Ambiente não reconhecido: ${error}`);
184
- }
185
- }
186
- static async post({ url, data, setToken = true }) {
187
- return await this.#axios.post(url, data, _api.headers({
162
+ static async post({ baseURLKey, url, data, setToken = true }) {
163
+ return await this.axios(baseURLKey).post(url, data, _api.headers({
188
164
  setToken: setToken
189
165
  }));
190
166
  }
191
- static async get({ url, params, setToken = true }) {
167
+ static async get({ baseURLKey, url, params, setToken = true }) {
192
168
  const queryParams = new URLSearchParams();
193
169
  if (params) Object.entries(params).forEach(([key, value])=>{
194
170
  if (null != value) queryParams.append(key, value);
195
171
  });
196
172
  const queryString = queryParams.toString();
197
173
  const fullUrl = queryString ? `${url}?${queryString}` : url;
198
- return await this.#axios.get(fullUrl, _api.headers({
174
+ return await this.axios(baseURLKey).get(fullUrl, _api.headers({
199
175
  setToken: setToken
200
176
  }));
201
177
  }
202
- static async patch({ url, data, setToken = true }) {
203
- return await this.#axios.patch(url, data, _api.headers({
178
+ static async patch({ baseURLKey, url, data, setToken = true }) {
179
+ return await this.axios(baseURLKey).patch(url, data, _api.headers({
204
180
  setToken: setToken
205
181
  }));
206
182
  }
207
- static async delete({ url }) {
208
- return await this.#axios.delete(url);
183
+ static async delete({ baseURLKey, url }) {
184
+ return await this.axios(baseURLKey).delete(url);
209
185
  }
210
186
  };
211
187
  static headers({ setToken = true }) {
@@ -640,6 +616,15 @@ class _hooks {
640
616
  }
641
617
  }
642
618
  const utils_hooks = new _hooks;
619
+ const _environment = class {
620
+ static set(props) {
621
+ window.sessionStorage.setItem("ENVIRONMENT", props);
622
+ }
623
+ static get get() {
624
+ return window.sessionStorage.getItem("ENVIRONMENT");
625
+ }
626
+ };
627
+ const utils_environment = _environment;
643
628
  const utils = {
644
629
  api: utils_api,
645
630
  data: utils_data,
@@ -3,24 +3,27 @@ declare const _api: {
3
3
  new (): {};
4
4
  servidor_pricipal: {
5
5
  new (): {};
6
- get "__#private@#axios"(): import("axios").AxiosInstance;
7
- resolve_base_url(): string | any;
8
- post({ url, data, setToken }: {
6
+ axios(key: string): import("axios").AxiosInstance;
7
+ post({ baseURLKey, url, data, setToken }: {
8
+ baseURLKey: string;
9
9
  url: string;
10
10
  data: any;
11
11
  setToken?: boolean;
12
12
  }): Promise<AxiosResponse<any, any, {}>>;
13
- get({ url, params, setToken }: {
13
+ get({ baseURLKey, url, params, setToken }: {
14
+ baseURLKey: string;
14
15
  url: string;
15
16
  params?: any;
16
17
  setToken?: boolean;
17
18
  }): Promise<AxiosResponse<any, any, {}>>;
18
- patch({ url, data, setToken }: {
19
+ patch({ baseURLKey, url, data, setToken }: {
20
+ baseURLKey: string;
19
21
  url: string;
20
22
  data: any;
21
23
  setToken?: boolean;
22
24
  }): Promise<AxiosResponse<any, any, {}>>;
23
- delete({ url }: {
25
+ delete({ baseURLKey, url }: {
26
+ baseURLKey: string;
24
27
  url: string;
25
28
  setToken?: boolean;
26
29
  }): Promise<AxiosResponse<any, any, {}>>;
@@ -4,24 +4,27 @@ declare const utils: {
4
4
  new (): {};
5
5
  servidor_pricipal: {
6
6
  new (): {};
7
- get "__#private@#axios"(): import("axios").AxiosInstance;
8
- resolve_base_url(): string | any;
9
- post({ url, data, setToken }: {
7
+ axios(key: string): import("axios").AxiosInstance;
8
+ post({ baseURLKey, url, data, setToken }: {
9
+ baseURLKey: string;
10
10
  url: string;
11
11
  data: any;
12
12
  setToken?: boolean;
13
13
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
14
- get({ url, params, setToken }: {
14
+ get({ baseURLKey, url, params, setToken }: {
15
+ baseURLKey: string;
15
16
  url: string;
16
17
  params?: any;
17
18
  setToken?: boolean;
18
19
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
19
- patch({ url, data, setToken }: {
20
+ patch({ baseURLKey, url, data, setToken }: {
21
+ baseURLKey: string;
20
22
  url: string;
21
23
  data: any;
22
24
  setToken?: boolean;
23
25
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
24
- delete({ url }: {
26
+ delete({ baseURLKey, url }: {
27
+ baseURLKey: string;
25
28
  url: string;
26
29
  setToken?: boolean;
27
30
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
@@ -224,66 +224,24 @@ const _session_storage = class _session_storage {
224
224
  };
225
225
  /* export default */ const utils_session_storage = (_session_storage);
226
226
 
227
- ;// CONCATENATED MODULE: ./src/utils/_environment.ts
228
- //BIBLIOTECAS
229
- //HELPERS
230
- //BANCO DE DADOS
231
- //SERVICES
232
- const _environment = class _environment {
233
- static set(props) {
234
- window.sessionStorage.setItem("ENVIRONMENT", props);
235
- return;
236
- }
237
- static get get() {
238
- return window.sessionStorage.getItem("ENVIRONMENT");
239
- }
240
- };
241
- /* export default */ const utils_environment = (_environment);
242
-
243
227
  ;// CONCATENATED MODULE: ./src/utils/_api.ts
244
228
 
245
229
 
246
-
247
230
  const _api_api = class _api {
248
231
  static servidor_pricipal = class servidor_pricipal {
249
- static get #axios() {
232
+ static axios(key) {
233
+ const baseURL = sessionStorage.getItem(key);
234
+ if (!baseURL) throw new Error("API não inicializada no service core");
250
235
  return external_axios_default().create({
251
- baseURL: this.resolve_base_url()
236
+ baseURL
252
237
  });
253
238
  }
254
- static resolve_base_url() {
255
- try {
256
- if (typeof window === "undefined") {
257
- throw new Error("resolveApiBaseURL must run in browser");
258
- }
259
- const { origin, hostname } = window.location;
260
- if (hostname.includes("navsoftware")) {
261
- const apiOrigin = origin.replace(/^https?:\/\/app/, (match)=>match.replace("app", "api"));
262
- return apiOrigin;
263
- }
264
- const apiOverride = utils_environment.get;
265
- if (apiOverride === "SANDBOX") {
266
- return "https://api-sandbox.navsoftware.com.br";
267
- }
268
- if (apiOverride === "PRODUCAO") {
269
- return "https://api.navsoftware.com.br";
270
- }
271
- if (apiOverride === "LOCALHOST") {
272
- return "http://localhost:8787";
273
- }
274
- if (hostname === "localhost" || hostname.startsWith("localhost")) {
275
- return "http://localhost:8787";
276
- }
277
- } catch (error) {
278
- throw new Error(`Ambiente não reconhecido: ${error}`);
279
- }
280
- }
281
- static async post({ url, data, setToken = true }) {
282
- return await this.#axios.post(url, data, _api.headers({
239
+ static async post({ baseURLKey, url, data, setToken = true }) {
240
+ return await this.axios(baseURLKey).post(url, data, _api.headers({
283
241
  setToken: setToken
284
242
  }));
285
243
  }
286
- static async get({ url, params, setToken = true }) {
244
+ static async get({ baseURLKey, url, params, setToken = true }) {
287
245
  const queryParams = new URLSearchParams();
288
246
  if (params) {
289
247
  Object.entries(params).forEach(([key, value])=>{
@@ -294,17 +252,17 @@ const _api_api = class _api {
294
252
  }
295
253
  const queryString = queryParams.toString();
296
254
  const fullUrl = queryString ? `${url}?${queryString}` : url;
297
- return await this.#axios.get(fullUrl, _api.headers({
255
+ return await this.axios(baseURLKey).get(fullUrl, _api.headers({
298
256
  setToken: setToken
299
257
  }));
300
258
  }
301
- static async patch({ url, data, setToken = true }) {
302
- return await this.#axios.patch(url, data, _api.headers({
259
+ static async patch({ baseURLKey, url, data, setToken = true }) {
260
+ return await this.axios(baseURLKey).patch(url, data, _api.headers({
303
261
  setToken: setToken
304
262
  }));
305
263
  }
306
- static async delete({ url }) {
307
- return await this.#axios.delete(url);
264
+ static async delete({ baseURLKey, url }) {
265
+ return await this.axios(baseURLKey).delete(url);
308
266
  }
309
267
  };
310
268
  static headers({ setToken = true }) {
@@ -828,6 +786,22 @@ class _hooks {
828
786
  }
829
787
  /* export default */ const utils_hooks = (new _hooks);
830
788
 
789
+ ;// CONCATENATED MODULE: ./src/utils/_environment.ts
790
+ //BIBLIOTECAS
791
+ //HELPERS
792
+ //BANCO DE DADOS
793
+ //SERVICES
794
+ const _environment = class _environment {
795
+ static set(props) {
796
+ window.sessionStorage.setItem("ENVIRONMENT", props);
797
+ return;
798
+ }
799
+ static get get() {
800
+ return window.sessionStorage.getItem("ENVIRONMENT");
801
+ }
802
+ };
803
+ /* export default */ const utils_environment = (_environment);
804
+
831
805
  ;// CONCATENATED MODULE: ./src/utils/index.ts
832
806
 
833
807
 
@@ -3,24 +3,27 @@ declare const _api: {
3
3
  new (): {};
4
4
  servidor_pricipal: {
5
5
  new (): {};
6
- get "__#private@#axios"(): import("axios").AxiosInstance;
7
- resolve_base_url(): string | any;
8
- post({ url, data, setToken }: {
6
+ axios(key: string): import("axios").AxiosInstance;
7
+ post({ baseURLKey, url, data, setToken }: {
8
+ baseURLKey: string;
9
9
  url: string;
10
10
  data: any;
11
11
  setToken?: boolean;
12
12
  }): Promise<AxiosResponse<any, any, {}>>;
13
- get({ url, params, setToken }: {
13
+ get({ baseURLKey, url, params, setToken }: {
14
+ baseURLKey: string;
14
15
  url: string;
15
16
  params?: any;
16
17
  setToken?: boolean;
17
18
  }): Promise<AxiosResponse<any, any, {}>>;
18
- patch({ url, data, setToken }: {
19
+ patch({ baseURLKey, url, data, setToken }: {
20
+ baseURLKey: string;
19
21
  url: string;
20
22
  data: any;
21
23
  setToken?: boolean;
22
24
  }): Promise<AxiosResponse<any, any, {}>>;
23
- delete({ url }: {
25
+ delete({ baseURLKey, url }: {
26
+ baseURLKey: string;
24
27
  url: string;
25
28
  setToken?: boolean;
26
29
  }): Promise<AxiosResponse<any, any, {}>>;
@@ -4,24 +4,27 @@ declare const utils: {
4
4
  new (): {};
5
5
  servidor_pricipal: {
6
6
  new (): {};
7
- get "__#private@#axios"(): import("axios").AxiosInstance;
8
- resolve_base_url(): string | any;
9
- post({ url, data, setToken }: {
7
+ axios(key: string): import("axios").AxiosInstance;
8
+ post({ baseURLKey, url, data, setToken }: {
9
+ baseURLKey: string;
10
10
  url: string;
11
11
  data: any;
12
12
  setToken?: boolean;
13
13
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
14
- get({ url, params, setToken }: {
14
+ get({ baseURLKey, url, params, setToken }: {
15
+ baseURLKey: string;
15
16
  url: string;
16
17
  params?: any;
17
18
  setToken?: boolean;
18
19
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
19
- patch({ url, data, setToken }: {
20
+ patch({ baseURLKey, url, data, setToken }: {
21
+ baseURLKey: string;
20
22
  url: string;
21
23
  data: any;
22
24
  setToken?: boolean;
23
25
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
24
- delete({ url }: {
26
+ delete({ baseURLKey, url }: {
27
+ baseURLKey: string;
25
28
  url: string;
26
29
  setToken?: boolean;
27
30
  }): Promise<import("axios").AxiosResponse<any, any, {}>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.77.0",
3
+ "version": "1.79.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {