@navservice/core 1.51.0 → 1.53.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.
@@ -5,7 +5,7 @@ class config_env {
5
5
  config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
6
6
  }
7
7
  static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
8
- return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
8
+ return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL?.trim();
9
9
  }
10
10
  }
11
11
  const src_config_env = config_env;
@@ -1,41 +1,16 @@
1
1
  import { AxiosResponse } from "axios";
2
- declare const _api: {
3
- new (): {};
4
- servidor_service_usuario: {
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 }: {
28
- setToken?: boolean;
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;
2
+ interface ApiClientOptions {
3
+ baseURL?: string;
4
+ withAuth?: boolean;
5
+ }
6
+ export default class api {
7
+ private axios;
8
+ private withAuth;
9
+ constructor({ baseURL, withAuth }: ApiClientOptions);
10
+ private set_bearer_token;
11
+ get<T = any>(url: string, params?: Record<string, any>): Promise<AxiosResponse<T>>;
12
+ post<T = any>(url: string, data?: any): Promise<AxiosResponse<T>>;
13
+ patch<T = any>(url: string, data?: any): Promise<AxiosResponse<T>>;
14
+ delete<T = any>(url: string): Promise<AxiosResponse<T>>;
15
+ }
16
+ export {};
@@ -1,44 +1,7 @@
1
+ import _api from "./_api";
1
2
  import _form from "./_form";
2
3
  declare const utils: {
3
- api: {
4
- new (): {};
5
- servidor_service_usuario: {
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
- };
4
+ api: typeof _api;
42
5
  data: {
43
6
  new (): {};
44
7
  YYYY_MM_DD_00_00_00(newData: string): string;
package/build/es/utils.js CHANGED
@@ -1,15 +1,5 @@
1
1
  import axios from "axios";
2
2
  import { useLayoutEffect, useState } from "react";
3
- class config_env {
4
- static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
5
- static init(config) {
6
- config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
7
- }
8
- static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
9
- return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
10
- }
11
- }
12
- const src_config_env = config_env;
13
3
  const _session_storage = class {
14
4
  static adicionar_item_session_storage({ chave, novoItem }) {
15
5
  try {
@@ -51,59 +41,53 @@ const _session_storage = class {
51
41
  }
52
42
  };
53
43
  const utils_session_storage = _session_storage;
54
- const _api_api = class _api {
55
- static servidor_service_usuario = class {
56
- static get #axios() {
57
- return axios.create({
58
- baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL
59
- });
60
- }
61
- static async post({ url, data, setToken = true }) {
62
- return await this.#axios.post(url, data, _api.headers({
63
- setToken: setToken
64
- }));
65
- }
66
- static async get({ url, params, setToken = true }) {
67
- const queryParams = new URLSearchParams();
68
- if (params) Object.entries(params).forEach(([key, value])=>{
69
- console.log('13');
70
- if (null != value) {
71
- console.log('14');
72
- queryParams.append(key, value);
73
- console.log('15');
74
- }
75
- });
76
- const queryString = queryParams.toString();
77
- const fullUrl = queryString ? `${url}?${queryString}` : url;
78
- return await this.#axios.get(fullUrl, _api.headers({
79
- setToken: setToken
80
- }));
81
- }
82
- static async patch({ url, data, setToken = true }) {
83
- return await this.#axios.patch(url, data, _api.headers({
84
- setToken: setToken
85
- }));
86
- }
87
- static async delete({ url }) {
88
- return await this.#axios.delete(url);
89
- }
90
- };
91
- static headers({ setToken = true }) {
92
- const get_auth_user = utils_session_storage.get_item_session_storage("auth_user");
93
- if (true === setToken) return {
44
+ class config_env {
45
+ static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
46
+ static init(config) {
47
+ config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
48
+ }
49
+ static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
50
+ return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL?.trim();
51
+ }
52
+ }
53
+ const src_config_env = config_env;
54
+ class api {
55
+ axios;
56
+ withAuth;
57
+ constructor({ baseURL, withAuth = true }){
58
+ this.withAuth = withAuth;
59
+ this.axios = axios.create({
60
+ baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL ?? baseURL,
94
61
  headers: {
95
- Authorization: `Bearer ${get_auth_user?.data?.usuario?.token}`,
96
- "Content-type": "application/json"
62
+ "Content-Type": "application/json"
97
63
  }
98
- };
99
- return {
100
- headers: {
101
- "Content-type": "application/json"
64
+ });
65
+ this.set_bearer_token();
66
+ }
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}`;
102
72
  }
103
- };
73
+ return config;
74
+ });
104
75
  }
105
- };
106
- const utils_api = _api_api;
76
+ get(url, params) {
77
+ return this.axios.get(url, {
78
+ params
79
+ });
80
+ }
81
+ post(url, data) {
82
+ return this.axios.post(url, data);
83
+ }
84
+ patch(url, data) {
85
+ return this.axios.patch(url, data);
86
+ }
87
+ delete(url) {
88
+ return this.axios.delete(url);
89
+ }
90
+ }
107
91
  const _data = class {
108
92
  static YYYY_MM_DD_00_00_00(newData) {
109
93
  let dataAtual = new Date();
@@ -521,7 +505,7 @@ class _hooks {
521
505
  }
522
506
  const utils_hooks = new _hooks;
523
507
  const utils = {
524
- api: utils_api,
508
+ api: api,
525
509
  data: utils_data,
526
510
  form: utils_form,
527
511
  geral: _geral,
@@ -62,7 +62,7 @@ class config_env {
62
62
  config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
63
63
  }
64
64
  static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
65
- return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
65
+ return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL?.trim();
66
66
  }
67
67
  }
68
68
  /* export default */ const src_config_env = (config_env);
@@ -1,41 +1,16 @@
1
1
  import { AxiosResponse } from "axios";
2
- declare const _api: {
3
- new (): {};
4
- servidor_service_usuario: {
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 }: {
28
- setToken?: boolean;
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;
2
+ interface ApiClientOptions {
3
+ baseURL?: string;
4
+ withAuth?: boolean;
5
+ }
6
+ export default class api {
7
+ private axios;
8
+ private withAuth;
9
+ constructor({ baseURL, withAuth }: ApiClientOptions);
10
+ private set_bearer_token;
11
+ get<T = any>(url: string, params?: Record<string, any>): Promise<AxiosResponse<T>>;
12
+ post<T = any>(url: string, data?: any): Promise<AxiosResponse<T>>;
13
+ patch<T = any>(url: string, data?: any): Promise<AxiosResponse<T>>;
14
+ delete<T = any>(url: string): Promise<AxiosResponse<T>>;
15
+ }
16
+ export {};
@@ -1,44 +1,7 @@
1
+ import _api from "./_api";
1
2
  import _form from "./_form";
2
3
  declare const utils: {
3
- api: {
4
- new (): {};
5
- servidor_service_usuario: {
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
- };
4
+ api: typeof _api;
42
5
  data: {
43
6
  new (): {};
44
7
  YYYY_MM_DD_00_00_00(newData: string): string;
@@ -57,18 +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/config_env/index.ts
61
- class config_env {
62
- static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
63
- static init(config) {
64
- config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
65
- }
66
- static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
67
- return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
68
- }
69
- }
70
- /* export default */ const src_config_env = (config_env);
71
-
72
60
  ;// CONCATENATED MODULE: ./src/utils/_session_storage.ts
73
61
  const _session_storage = class _session_storage {
74
62
  static adicionar_item_session_storage({ chave, novoItem }) {
@@ -112,68 +100,61 @@ const _session_storage = class _session_storage {
112
100
  };
113
101
  /* export default */ const utils_session_storage = (_session_storage);
114
102
 
103
+ ;// CONCATENATED MODULE: ./src/config_env/index.ts
104
+ class config_env {
105
+ static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
106
+ static init(config) {
107
+ config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
108
+ }
109
+ static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
110
+ return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL?.trim();
111
+ }
112
+ }
113
+ /* export default */ const src_config_env = (config_env);
114
+
115
115
  ;// CONCATENATED MODULE: ./src/utils/_api.ts
116
116
 
117
117
 
118
118
 
119
- const _api_api = class _api {
120
- static servidor_service_usuario = class servidor_service_usuario {
121
- static get #axios() {
122
- return external_axios_default().create({
123
- baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL
124
- });
125
- }
126
- static async post({ url, data, setToken = true }) {
127
- return await this.#axios.post(url, data, _api.headers({
128
- setToken: setToken
129
- }));
130
- }
131
- static async get({ url, params, setToken = true }) {
132
- const queryParams = new URLSearchParams();
133
- if (params) {
134
- Object.entries(params).forEach(([key, value])=>{
135
- console.log('13');
136
- if (value !== null && value !== undefined) {
137
- console.log('14');
138
- queryParams.append(key, value);
139
- console.log('15');
140
- }
141
- });
119
+ class api {
120
+ axios;
121
+ withAuth;
122
+ constructor({ baseURL, withAuth = true }){
123
+ this.withAuth = withAuth;
124
+ this.axios = external_axios_default().create({
125
+ baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL ?? baseURL,
126
+ headers: {
127
+ "Content-Type": "application/json"
142
128
  }
143
- const queryString = queryParams.toString();
144
- const fullUrl = queryString ? `${url}?${queryString}` : url;
145
- return await this.#axios.get(fullUrl, _api.headers({
146
- setToken: setToken
147
- }));
148
- }
149
- static async patch({ url, data, setToken = true }) {
150
- return await this.#axios.patch(url, data, _api.headers({
151
- setToken: setToken
152
- }));
153
- }
154
- static async delete({ url }) {
155
- return await this.#axios.delete(url);
156
- }
157
- };
158
- static headers({ setToken = true }) {
159
- const get_auth_user = utils_session_storage.get_item_session_storage("auth_user");
160
- if (setToken === true) {
161
- return {
162
- headers: {
163
- Authorization: `Bearer ${get_auth_user?.data?.usuario?.token}`,
164
- "Content-type": "application/json"
165
- }
166
- };
167
- } else {
168
- return {
169
- headers: {
170
- "Content-type": "application/json"
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}`;
171
138
  }
172
- };
173
- }
139
+ }
140
+ return config;
141
+ });
174
142
  }
175
- };
176
- /* export default */ const utils_api = (_api_api);
143
+ get(url, params) {
144
+ return this.axios.get(url, {
145
+ params
146
+ });
147
+ }
148
+ post(url, data) {
149
+ return this.axios.post(url, data);
150
+ }
151
+ patch(url, data) {
152
+ return this.axios.patch(url, data);
153
+ }
154
+ delete(url) {
155
+ return this.axios.delete(url);
156
+ }
157
+ }
177
158
 
178
159
  ;// CONCATENATED MODULE: ./src/utils/_data.ts
179
160
  const _data = class _data {
@@ -687,7 +668,7 @@ class _hooks {
687
668
 
688
669
 
689
670
  const utils = {
690
- api: utils_api,
671
+ api: api,
691
672
  data: utils_data,
692
673
  form: utils_form,
693
674
  geral: _geral,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.51.0",
3
+ "version": "1.53.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {