@navservice/core 1.58.0 → 1.60.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.
@@ -1,25 +1,41 @@
1
1
  import { AxiosResponse } from "axios";
2
- export default class api {
3
- private static axios;
4
- private static withAuth;
5
- private static get_headers;
6
- static get<T = any>({ url, params, setToken }: {
7
- url: string;
8
- params?: Record<string, any>;
2
+ declare const _api: {
3
+ new (): {};
4
+ servidor_pricipal: {
5
+ new (): {};
6
+ get "__#private@#axios"(): import("axios").AxiosInstance;
7
+ post({ url, data, setToken }: {
8
+ url: string;
9
+ data: any;
10
+ setToken?: boolean;
11
+ }): Promise<AxiosResponse<any, any, {}>>;
12
+ get({ url, params, setToken }: {
13
+ url: string;
14
+ params?: any;
15
+ setToken?: boolean;
16
+ }): Promise<AxiosResponse<any, any, {}>>;
17
+ patch({ url, data, setToken }: {
18
+ url: string;
19
+ data: any;
20
+ setToken?: boolean;
21
+ }): Promise<AxiosResponse<any, any, {}>>;
22
+ delete({ url }: {
23
+ url: string;
24
+ setToken?: boolean;
25
+ }): Promise<AxiosResponse<any, any, {}>>;
26
+ };
27
+ headers({ setToken }: {
9
28
  setToken?: boolean;
10
- }): Promise<AxiosResponse<T>>;
11
- static post<T = any>({ url, data, setToken }: {
12
- url: string;
13
- data?: any;
14
- setToken?: boolean;
15
- }): Promise<AxiosResponse<T>>;
16
- static patch<T = any>({ url, data, setToken }: {
17
- url: string;
18
- data?: any;
19
- setToken?: boolean;
20
- }): Promise<AxiosResponse<T>>;
21
- static delete<T = any>({ url, setToken }: {
22
- url: string;
23
- setToken?: boolean;
24
- }): Promise<AxiosResponse<T>>;
25
- }
29
+ }): {
30
+ headers: {
31
+ Authorization: string;
32
+ "Content-type": string;
33
+ };
34
+ } | {
35
+ headers: {
36
+ "Content-type": string;
37
+ Authorization?: undefined;
38
+ };
39
+ };
40
+ };
41
+ export default _api;
@@ -1,7 +1,44 @@
1
- import _api from "./_api";
2
1
  import _form from "./_form";
3
2
  declare const utils: {
4
- api: typeof _api;
3
+ api: {
4
+ new (): {};
5
+ servidor_pricipal: {
6
+ new (): {};
7
+ get "__#private@#axios"(): import("axios").AxiosInstance;
8
+ post({ url, data, setToken }: {
9
+ url: string;
10
+ data: any;
11
+ setToken?: boolean;
12
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
13
+ get({ url, params, setToken }: {
14
+ url: string;
15
+ params?: any;
16
+ setToken?: boolean;
17
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
18
+ patch({ url, data, setToken }: {
19
+ url: string;
20
+ data: any;
21
+ setToken?: boolean;
22
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
23
+ delete({ url }: {
24
+ url: string;
25
+ setToken?: boolean;
26
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
27
+ };
28
+ headers({ setToken }: {
29
+ setToken?: boolean;
30
+ }): {
31
+ headers: {
32
+ Authorization: string;
33
+ "Content-type": string;
34
+ };
35
+ } | {
36
+ headers: {
37
+ "Content-type": string;
38
+ Authorization?: undefined;
39
+ };
40
+ };
41
+ };
5
42
  data: {
6
43
  new (): {};
7
44
  YYYY_MM_DD_00_00_00(newData: string): string;
package/build/es/utils.js CHANGED
@@ -1,46 +1,5 @@
1
1
  import axios from "axios";
2
2
  import { useLayoutEffect, useState } from "react";
3
- const _session_storage = class {
4
- static adicionar_item_session_storage({ chave, novoItem }) {
5
- try {
6
- const valorAtual = window.sessionStorage.getItem(chave);
7
- const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
8
- const newDataItem = {
9
- ...listaAtual,
10
- ...novoItem
11
- };
12
- window.sessionStorage.setItem(chave, JSON.stringify(newDataItem));
13
- } catch (error) {
14
- console.error(error);
15
- }
16
- }
17
- static set_session_storage_sem_incremento({ chave, novoItem }) {
18
- try {
19
- window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
20
- } catch (error) {
21
- console.error(error);
22
- }
23
- }
24
- static get_item_session_storage(chave) {
25
- try {
26
- if ("undefined" != typeof window) {
27
- const valorAtual = window.sessionStorage.getItem(chave);
28
- return valorAtual ? JSON.parse(valorAtual) : valorAtual;
29
- }
30
- return;
31
- } catch (error) {
32
- console.error(error);
33
- }
34
- }
35
- static remover_item_session_storage(chave) {
36
- try {
37
- window.sessionStorage.removeItem(chave);
38
- } catch (error) {
39
- console.error(error);
40
- }
41
- }
42
- };
43
- const utils_session_storage = _session_storage;
44
3
  class config_env {
45
4
  static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
46
5
  static init(config) {
@@ -51,46 +10,6 @@ class config_env {
51
10
  }
52
11
  }
53
12
  const src_config_env = config_env;
54
- class api {
55
- static axios = axios.create({
56
- baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL,
57
- headers: {
58
- "Content-Type": "application/json"
59
- }
60
- });
61
- static withAuth = true;
62
- static get_headers(setToken) {
63
- if (true === setToken && true === this.withAuth) {
64
- const auth = utils_session_storage.get_item_session_storage("auth_user");
65
- return {
66
- headers: {
67
- Authorization: auth?.data?.usuario?.token ? `Bearer ${auth.data.usuario.token}` : void 0,
68
- "Content-Type": "application/json"
69
- }
70
- };
71
- }
72
- return {
73
- headers: {
74
- "Content-Type": "application/json"
75
- }
76
- };
77
- }
78
- static async get({ url, params, setToken = true }) {
79
- return this.axios.get(url, {
80
- params,
81
- ...this.get_headers(setToken)
82
- });
83
- }
84
- static async post({ url, data, setToken = true }) {
85
- return this.axios.post(url, data, this.get_headers(setToken));
86
- }
87
- static async patch({ url, data, setToken = true }) {
88
- return this.axios.patch(url, data, this.get_headers(setToken));
89
- }
90
- static async delete({ url, setToken = true }) {
91
- return this.axios.delete(url, this.get_headers(setToken));
92
- }
93
- }
94
13
  const _data = class {
95
14
  static YYYY_MM_DD_00_00_00(newData) {
96
15
  let dataAtual = new Date();
@@ -436,6 +355,47 @@ const _update_context = class {
436
355
  }
437
356
  };
438
357
  const utils_update_context = _update_context;
358
+ const _session_storage = class {
359
+ static adicionar_item_session_storage({ chave, novoItem }) {
360
+ try {
361
+ const valorAtual = window.sessionStorage.getItem(chave);
362
+ const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
363
+ const newDataItem = {
364
+ ...listaAtual,
365
+ ...novoItem
366
+ };
367
+ window.sessionStorage.setItem(chave, JSON.stringify(newDataItem));
368
+ } catch (error) {
369
+ console.error(error);
370
+ }
371
+ }
372
+ static set_session_storage_sem_incremento({ chave, novoItem }) {
373
+ try {
374
+ window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
375
+ } catch (error) {
376
+ console.error(error);
377
+ }
378
+ }
379
+ static get_item_session_storage(chave) {
380
+ try {
381
+ if ("undefined" != typeof window) {
382
+ const valorAtual = window.sessionStorage.getItem(chave);
383
+ return valorAtual ? JSON.parse(valorAtual) : valorAtual;
384
+ }
385
+ return;
386
+ } catch (error) {
387
+ console.error(error);
388
+ }
389
+ }
390
+ static remover_item_session_storage(chave) {
391
+ try {
392
+ window.sessionStorage.removeItem(chave);
393
+ } catch (error) {
394
+ console.error(error);
395
+ }
396
+ }
397
+ };
398
+ const utils_session_storage = _session_storage;
439
399
  const _sistema = {
440
400
  empresa: {
441
401
  nome: "Nav Software",
@@ -508,7 +468,7 @@ class _hooks {
508
468
  }
509
469
  const utils_hooks = new _hooks;
510
470
  const utils = {
511
- api: api,
471
+ api: utils_api,
512
472
  data: utils_data,
513
473
  form: utils_form,
514
474
  geral: _geral,
@@ -519,4 +479,64 @@ const utils = {
519
479
  hooks: utils_hooks
520
480
  };
521
481
  const src_utils = utils;
522
- export { src_utils as default };
482
+ const _api_api = class _api {
483
+ static servidor_pricipal = class {
484
+ static get #axios() {
485
+ return axios.create({
486
+ baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL
487
+ });
488
+ }
489
+ static async post({ url, data, setToken = true }) {
490
+ return await this.#axios.post(url, data, _api.headers({
491
+ setToken: setToken
492
+ }));
493
+ }
494
+ static async get({ url, params, setToken = true }) {
495
+ const queryParams = new URLSearchParams();
496
+ if (params) Object.entries(params).forEach(([key, value])=>{
497
+ if (null != value) queryParams.append(key, value);
498
+ });
499
+ const queryString = queryParams.toString();
500
+ const fullUrl = queryString ? `${url}?${queryString}` : url;
501
+ return await this.#axios.get(fullUrl, _api.headers({
502
+ setToken: setToken
503
+ }));
504
+ }
505
+ static async patch({ url, data, setToken = true }) {
506
+ return await this.#axios.patch(url, data, _api.headers({
507
+ setToken: setToken
508
+ }));
509
+ }
510
+ static async delete({ url }) {
511
+ return await this.#axios.delete(url);
512
+ }
513
+ };
514
+ static headers({ setToken = true }) {
515
+ const get_auth_user = src_utils.session_sorage.get_item_session_storage("auth_user");
516
+ if (true === setToken) return {
517
+ headers: {
518
+ Authorization: `Bearer ${get_auth_user?.data?.usuario?.token}`,
519
+ "Content-type": "application/json"
520
+ }
521
+ };
522
+ return {
523
+ headers: {
524
+ "Content-type": "application/json"
525
+ }
526
+ };
527
+ }
528
+ };
529
+ const utils_api = _api_api;
530
+ const utils_utils = {
531
+ api: utils_api,
532
+ data: utils_data,
533
+ form: utils_form,
534
+ geral: _geral,
535
+ local_storage: utils_local_storage,
536
+ update_context: utils_update_context,
537
+ session_sorage: utils_session_storage,
538
+ sistema: utils_sistema,
539
+ hooks: utils_hooks
540
+ };
541
+ const src_utils_0 = utils_utils;
542
+ export { src_utils_0 as default };
@@ -1,25 +1,41 @@
1
1
  import { AxiosResponse } from "axios";
2
- export default class api {
3
- private static axios;
4
- private static withAuth;
5
- private static get_headers;
6
- static get<T = any>({ url, params, setToken }: {
7
- url: string;
8
- params?: Record<string, any>;
2
+ declare const _api: {
3
+ new (): {};
4
+ servidor_pricipal: {
5
+ new (): {};
6
+ get "__#private@#axios"(): import("axios").AxiosInstance;
7
+ post({ url, data, setToken }: {
8
+ url: string;
9
+ data: any;
10
+ setToken?: boolean;
11
+ }): Promise<AxiosResponse<any, any, {}>>;
12
+ get({ url, params, setToken }: {
13
+ url: string;
14
+ params?: any;
15
+ setToken?: boolean;
16
+ }): Promise<AxiosResponse<any, any, {}>>;
17
+ patch({ url, data, setToken }: {
18
+ url: string;
19
+ data: any;
20
+ setToken?: boolean;
21
+ }): Promise<AxiosResponse<any, any, {}>>;
22
+ delete({ url }: {
23
+ url: string;
24
+ setToken?: boolean;
25
+ }): Promise<AxiosResponse<any, any, {}>>;
26
+ };
27
+ headers({ setToken }: {
9
28
  setToken?: boolean;
10
- }): Promise<AxiosResponse<T>>;
11
- static post<T = any>({ url, data, setToken }: {
12
- url: string;
13
- data?: any;
14
- setToken?: boolean;
15
- }): Promise<AxiosResponse<T>>;
16
- static patch<T = any>({ url, data, setToken }: {
17
- url: string;
18
- data?: any;
19
- setToken?: boolean;
20
- }): Promise<AxiosResponse<T>>;
21
- static delete<T = any>({ url, setToken }: {
22
- url: string;
23
- setToken?: boolean;
24
- }): Promise<AxiosResponse<T>>;
25
- }
29
+ }): {
30
+ headers: {
31
+ Authorization: string;
32
+ "Content-type": string;
33
+ };
34
+ } | {
35
+ headers: {
36
+ "Content-type": string;
37
+ Authorization?: undefined;
38
+ };
39
+ };
40
+ };
41
+ export default _api;
@@ -1,7 +1,44 @@
1
- import _api from "./_api";
2
1
  import _form from "./_form";
3
2
  declare const utils: {
4
- api: typeof _api;
3
+ api: {
4
+ new (): {};
5
+ servidor_pricipal: {
6
+ new (): {};
7
+ get "__#private@#axios"(): import("axios").AxiosInstance;
8
+ post({ url, data, setToken }: {
9
+ url: string;
10
+ data: any;
11
+ setToken?: boolean;
12
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
13
+ get({ url, params, setToken }: {
14
+ url: string;
15
+ params?: any;
16
+ setToken?: boolean;
17
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
18
+ patch({ url, data, setToken }: {
19
+ url: string;
20
+ data: any;
21
+ setToken?: boolean;
22
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
23
+ delete({ url }: {
24
+ url: string;
25
+ setToken?: boolean;
26
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
27
+ };
28
+ headers({ setToken }: {
29
+ setToken?: boolean;
30
+ }): {
31
+ headers: {
32
+ Authorization: string;
33
+ "Content-type": string;
34
+ };
35
+ } | {
36
+ headers: {
37
+ "Content-type": string;
38
+ Authorization?: undefined;
39
+ };
40
+ };
41
+ };
5
42
  data: {
6
43
  new (): {};
7
44
  YYYY_MM_DD_00_00_00(newData: string): string;
@@ -57,49 +57,6 @@ __webpack_require__.d(__webpack_exports__, {
57
57
  ;// CONCATENATED MODULE: external "axios"
58
58
  const external_axios_namespaceObject = require("axios");
59
59
  var external_axios_default = /*#__PURE__*/__webpack_require__.n(external_axios_namespaceObject);
60
- ;// CONCATENATED MODULE: ./src/utils/_session_storage.ts
61
- const _session_storage = class _session_storage {
62
- static adicionar_item_session_storage({ chave, novoItem }) {
63
- try {
64
- const valorAtual = window.sessionStorage.getItem(chave);
65
- const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
66
- const newDataItem = {
67
- ...listaAtual,
68
- ...novoItem
69
- };
70
- window.sessionStorage.setItem(chave, JSON.stringify(newDataItem));
71
- } catch (error) {
72
- console.error(error);
73
- }
74
- }
75
- static set_session_storage_sem_incremento({ chave, novoItem }) {
76
- try {
77
- window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
78
- } catch (error) {
79
- console.error(error);
80
- }
81
- }
82
- static get_item_session_storage(chave) {
83
- try {
84
- if (typeof window !== "undefined") {
85
- const valorAtual = window.sessionStorage.getItem(chave);
86
- return valorAtual ? JSON.parse(valorAtual) : valorAtual;
87
- }
88
- return;
89
- } catch (error) {
90
- console.error(error);
91
- }
92
- }
93
- static remover_item_session_storage(chave) {
94
- try {
95
- window.sessionStorage.removeItem(chave);
96
- } catch (error) {
97
- console.error(error);
98
- }
99
- }
100
- };
101
- /* export default */ const utils_session_storage = (_session_storage);
102
-
103
60
  ;// CONCATENATED MODULE: ./src/config_env/index.ts
104
61
  class config_env {
105
62
  static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
@@ -116,46 +73,61 @@ class config_env {
116
73
 
117
74
 
118
75
 
119
- class api {
120
- static axios = external_axios_default().create({
121
- baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL,
122
- headers: {
123
- "Content-Type": "application/json"
124
- }
125
- });
126
- static withAuth = true;
127
- static get_headers(setToken) {
128
- if (setToken === true && this.withAuth === true) {
129
- const auth = utils_session_storage.get_item_session_storage("auth_user");
76
+ const _api_api = class _api {
77
+ static servidor_pricipal = class servidor_pricipal {
78
+ static get #axios() {
79
+ return external_axios_default().create({
80
+ baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL
81
+ });
82
+ }
83
+ static async post({ url, data, setToken = true }) {
84
+ return await this.#axios.post(url, data, _api.headers({
85
+ setToken: setToken
86
+ }));
87
+ }
88
+ static async get({ url, params, setToken = true }) {
89
+ const queryParams = new URLSearchParams();
90
+ if (params) {
91
+ Object.entries(params).forEach(([key, value])=>{
92
+ if (value !== null && value !== undefined) {
93
+ queryParams.append(key, value);
94
+ }
95
+ });
96
+ }
97
+ const queryString = queryParams.toString();
98
+ const fullUrl = queryString ? `${url}?${queryString}` : url;
99
+ return await this.#axios.get(fullUrl, _api.headers({
100
+ setToken: setToken
101
+ }));
102
+ }
103
+ static async patch({ url, data, setToken = true }) {
104
+ return await this.#axios.patch(url, data, _api.headers({
105
+ setToken: setToken
106
+ }));
107
+ }
108
+ static async delete({ url }) {
109
+ return await this.#axios.delete(url);
110
+ }
111
+ };
112
+ static headers({ setToken = true }) {
113
+ const get_auth_user = src_utils.session_sorage.get_item_session_storage("auth_user");
114
+ if (setToken === true) {
130
115
  return {
131
116
  headers: {
132
- Authorization: auth?.data?.usuario?.token ? `Bearer ${auth.data.usuario.token}` : undefined,
133
- "Content-Type": "application/json"
117
+ Authorization: `Bearer ${get_auth_user?.data?.usuario?.token}`,
118
+ "Content-type": "application/json"
119
+ }
120
+ };
121
+ } else {
122
+ return {
123
+ headers: {
124
+ "Content-type": "application/json"
134
125
  }
135
126
  };
136
127
  }
137
- return {
138
- headers: {
139
- "Content-Type": "application/json"
140
- }
141
- };
142
- }
143
- static async get({ url, params, setToken = true }) {
144
- return this.axios.get(url, {
145
- params,
146
- ...this.get_headers(setToken)
147
- });
148
- }
149
- static async post({ url, data, setToken = true }) {
150
- return this.axios.post(url, data, this.get_headers(setToken));
151
- }
152
- static async patch({ url, data, setToken = true }) {
153
- return this.axios.patch(url, data, this.get_headers(setToken));
154
128
  }
155
- static async delete({ url, setToken = true }) {
156
- return this.axios.delete(url, this.get_headers(setToken));
157
- }
158
- }
129
+ };
130
+ /* export default */ const utils_api = (_api_api);
159
131
 
160
132
  ;// CONCATENATED MODULE: ./src/utils/_data.ts
161
133
  const _data = class _data {
@@ -580,6 +552,49 @@ const _update_context = class _update_context {
580
552
  };
581
553
  /* export default */ const utils_update_context = (_update_context);
582
554
 
555
+ ;// CONCATENATED MODULE: ./src/utils/_session_storage.ts
556
+ const _session_storage = class _session_storage {
557
+ static adicionar_item_session_storage({ chave, novoItem }) {
558
+ try {
559
+ const valorAtual = window.sessionStorage.getItem(chave);
560
+ const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
561
+ const newDataItem = {
562
+ ...listaAtual,
563
+ ...novoItem
564
+ };
565
+ window.sessionStorage.setItem(chave, JSON.stringify(newDataItem));
566
+ } catch (error) {
567
+ console.error(error);
568
+ }
569
+ }
570
+ static set_session_storage_sem_incremento({ chave, novoItem }) {
571
+ try {
572
+ window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
573
+ } catch (error) {
574
+ console.error(error);
575
+ }
576
+ }
577
+ static get_item_session_storage(chave) {
578
+ try {
579
+ if (typeof window !== "undefined") {
580
+ const valorAtual = window.sessionStorage.getItem(chave);
581
+ return valorAtual ? JSON.parse(valorAtual) : valorAtual;
582
+ }
583
+ return;
584
+ } catch (error) {
585
+ console.error(error);
586
+ }
587
+ }
588
+ static remover_item_session_storage(chave) {
589
+ try {
590
+ window.sessionStorage.removeItem(chave);
591
+ } catch (error) {
592
+ console.error(error);
593
+ }
594
+ }
595
+ };
596
+ /* export default */ const utils_session_storage = (_session_storage);
597
+
583
598
  ;// CONCATENATED MODULE: ./src/utils/_sistema.ts
584
599
  const _sistema = {
585
600
  empresa: {
@@ -669,7 +684,7 @@ class _hooks {
669
684
 
670
685
 
671
686
  const utils = {
672
- api: api,
687
+ api: utils_api,
673
688
  data: utils_data,
674
689
  form: utils_form,
675
690
  geral: _geral,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.58.0",
3
+ "version": "1.60.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {