@navservice/core 1.51.0 → 1.52.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,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,43 @@ 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 api {
45
+ axios;
46
+ withAuth;
47
+ constructor({ baseURL, withAuth = true }){
48
+ this.withAuth = withAuth;
49
+ this.axios = axios.create({
50
+ baseURL: baseURL,
94
51
  headers: {
95
- Authorization: `Bearer ${get_auth_user?.data?.usuario?.token}`,
96
- "Content-type": "application/json"
52
+ "Content-Type": "application/json"
97
53
  }
98
- };
99
- return {
100
- headers: {
101
- "Content-type": "application/json"
54
+ });
55
+ this.set_bearer_token();
56
+ }
57
+ set_bearer_token() {
58
+ this.axios.interceptors.request.use((config)=>{
59
+ if (this.withAuth) {
60
+ const auth = utils_session_storage.get_item_session_storage("auth_user");
61
+ if (auth?.data?.usuario?.token) config.headers.Authorization = `Bearer ${auth.data.usuario.token}`;
102
62
  }
103
- };
63
+ return config;
64
+ });
104
65
  }
105
- };
106
- const utils_api = _api_api;
66
+ get(url, params) {
67
+ return this.axios.get(url, {
68
+ params
69
+ });
70
+ }
71
+ post(url, data) {
72
+ return this.axios.post(url, data);
73
+ }
74
+ patch(url, data) {
75
+ return this.axios.patch(url, data);
76
+ }
77
+ delete(url) {
78
+ return this.axios.delete(url);
79
+ }
80
+ }
107
81
  const _data = class {
108
82
  static YYYY_MM_DD_00_00_00(newData) {
109
83
  let dataAtual = new Date();
@@ -521,7 +495,7 @@ class _hooks {
521
495
  }
522
496
  const utils_hooks = new _hooks;
523
497
  const utils = {
524
- api: utils_api,
498
+ api: api,
525
499
  data: utils_data,
526
500
  form: utils_form,
527
501
  geral: _geral,
@@ -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 }) {
@@ -115,65 +103,45 @@ const _session_storage = class _session_storage {
115
103
  ;// CONCATENATED MODULE: ./src/utils/_api.ts
116
104
 
117
105
 
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
- });
106
+ class api {
107
+ axios;
108
+ withAuth;
109
+ constructor({ baseURL, withAuth = true }){
110
+ this.withAuth = withAuth;
111
+ this.axios = external_axios_default().create({
112
+ baseURL: baseURL,
113
+ headers: {
114
+ "Content-Type": "application/json"
142
115
  }
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"
116
+ });
117
+ this.set_bearer_token();
118
+ }
119
+ set_bearer_token() {
120
+ this.axios.interceptors.request.use((config)=>{
121
+ if (this.withAuth) {
122
+ const auth = utils_session_storage.get_item_session_storage("auth_user");
123
+ if (auth?.data?.usuario?.token) {
124
+ config.headers.Authorization = `Bearer ${auth.data.usuario.token}`;
171
125
  }
172
- };
173
- }
126
+ }
127
+ return config;
128
+ });
174
129
  }
175
- };
176
- /* export default */ const utils_api = (_api_api);
130
+ get(url, params) {
131
+ return this.axios.get(url, {
132
+ params
133
+ });
134
+ }
135
+ post(url, data) {
136
+ return this.axios.post(url, data);
137
+ }
138
+ patch(url, data) {
139
+ return this.axios.patch(url, data);
140
+ }
141
+ delete(url) {
142
+ return this.axios.delete(url);
143
+ }
144
+ }
177
145
 
178
146
  ;// CONCATENATED MODULE: ./src/utils/_data.ts
179
147
  const _data = class _data {
@@ -687,7 +655,7 @@ class _hooks {
687
655
 
688
656
 
689
657
  const utils = {
690
- api: utils_api,
658
+ api: api,
691
659
  data: utils_data,
692
660
  form: utils_form,
693
661
  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.52.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {