@navservice/core 1.59.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
- import { AxiosInstance, AxiosResponse } from "axios";
2
- export default class api {
3
- static get axios(): AxiosInstance;
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>;
1
+ import { AxiosResponse } from "axios";
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,48 +10,6 @@ class config_env {
51
10
  }
52
11
  }
53
12
  const src_config_env = config_env;
54
- class api {
55
- static get axios() {
56
- return axios.create({
57
- baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL,
58
- headers: {
59
- "Content-Type": "application/json"
60
- }
61
- });
62
- }
63
- static withAuth = true;
64
- static get_headers(setToken) {
65
- if (true === setToken && true === this.withAuth) {
66
- const auth = utils_session_storage.get_item_session_storage("auth_user");
67
- return {
68
- headers: {
69
- Authorization: auth?.data?.usuario?.token ? `Bearer ${auth.data.usuario.token}` : void 0,
70
- "Content-Type": "application/json"
71
- }
72
- };
73
- }
74
- return {
75
- headers: {
76
- "Content-Type": "application/json"
77
- }
78
- };
79
- }
80
- static async get({ url, params, setToken = true }) {
81
- return this.axios.get(url, {
82
- params,
83
- ...this.get_headers(setToken)
84
- });
85
- }
86
- static async post({ url, data, setToken = true }) {
87
- return this.axios.post(url, data, this.get_headers(setToken));
88
- }
89
- static async patch({ url, data, setToken = true }) {
90
- return this.axios.patch(url, data, this.get_headers(setToken));
91
- }
92
- static async delete({ url, setToken = true }) {
93
- return this.axios.delete(url, this.get_headers(setToken));
94
- }
95
- }
96
13
  const _data = class {
97
14
  static YYYY_MM_DD_00_00_00(newData) {
98
15
  let dataAtual = new Date();
@@ -438,6 +355,47 @@ const _update_context = class {
438
355
  }
439
356
  };
440
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;
441
399
  const _sistema = {
442
400
  empresa: {
443
401
  nome: "Nav Software",
@@ -510,7 +468,7 @@ class _hooks {
510
468
  }
511
469
  const utils_hooks = new _hooks;
512
470
  const utils = {
513
- api: api,
471
+ api: utils_api,
514
472
  data: utils_data,
515
473
  form: utils_form,
516
474
  geral: _geral,
@@ -521,4 +479,64 @@ const utils = {
521
479
  hooks: utils_hooks
522
480
  };
523
481
  const src_utils = utils;
524
- 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
- import { AxiosInstance, AxiosResponse } from "axios";
2
- export default class api {
3
- static get axios(): AxiosInstance;
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>;
1
+ import { AxiosResponse } from "axios";
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,48 +73,61 @@ class config_env {
116
73
 
117
74
 
118
75
 
119
- class api {
120
- static get axios() {
121
- return external_axios_default().create({
122
- baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL,
123
- headers: {
124
- "Content-Type": "application/json"
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
+ });
125
96
  }
126
- });
127
- }
128
- static withAuth = true;
129
- static get_headers(setToken) {
130
- if (setToken === true && this.withAuth === true) {
131
- const auth = utils_session_storage.get_item_session_storage("auth_user");
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) {
132
115
  return {
133
116
  headers: {
134
- Authorization: auth?.data?.usuario?.token ? `Bearer ${auth.data.usuario.token}` : undefined,
135
- "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"
136
125
  }
137
126
  };
138
127
  }
139
- return {
140
- headers: {
141
- "Content-Type": "application/json"
142
- }
143
- };
144
- }
145
- static async get({ url, params, setToken = true }) {
146
- return this.axios.get(url, {
147
- params,
148
- ...this.get_headers(setToken)
149
- });
150
- }
151
- static async post({ url, data, setToken = true }) {
152
- return this.axios.post(url, data, this.get_headers(setToken));
153
128
  }
154
- static async patch({ url, data, setToken = true }) {
155
- return this.axios.patch(url, data, this.get_headers(setToken));
156
- }
157
- static async delete({ url, setToken = true }) {
158
- return this.axios.delete(url, this.get_headers(setToken));
159
- }
160
- }
129
+ };
130
+ /* export default */ const utils_api = (_api_api);
161
131
 
162
132
  ;// CONCATENATED MODULE: ./src/utils/_data.ts
163
133
  const _data = class _data {
@@ -582,6 +552,49 @@ const _update_context = class _update_context {
582
552
  };
583
553
  /* export default */ const utils_update_context = (_update_context);
584
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
+
585
598
  ;// CONCATENATED MODULE: ./src/utils/_sistema.ts
586
599
  const _sistema = {
587
600
  empresa: {
@@ -671,7 +684,7 @@ class _hooks {
671
684
 
672
685
 
673
686
  const utils = {
674
- api: api,
687
+ api: utils_api,
675
688
  data: utils_data,
676
689
  form: utils_form,
677
690
  geral: _geral,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.59.0",
3
+ "version": "1.60.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {