@designliquido/delegua-http 0.1.0 → 0.1.2

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,11 +1,12 @@
1
1
  import { AxiosInstance, RawAxiosRequestHeaders } from "axios";
2
2
  import { RespostaHttp } from "./resposta-http";
3
+ import { ArgumentoInterface } from "./interfaces";
3
4
  export declare class ClienteHttp {
4
5
  instanciaAxios: AxiosInstance;
5
6
  constructor(urlBase?: string, tempoMaximo?: number, cabecalhos?: any);
6
- requisicaoGet(sufixoUrl: string, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
7
- requisicaoPost(sufixoUrl: string, corpo: any, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
8
- requisicaoPut(sufixoUrl: string, corpo: any, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
9
- requisicaoDelete(sufixoUrl: string, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
10
- requisicaoPatch(sufixoUrl: string, corpo: any, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
7
+ requisicaoGet(sufixoUrl: string | ArgumentoInterface, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
8
+ requisicaoPost(sufixoUrl: string | ArgumentoInterface, corpo: any, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
9
+ requisicaoPut(sufixoUrl: string | ArgumentoInterface, corpo: any, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
10
+ requisicaoDelete(sufixoUrl: string | ArgumentoInterface, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
11
+ requisicaoPatch(sufixoUrl: string | ArgumentoInterface, corpo: any, cabecalhos?: RawAxiosRequestHeaders): Promise<RespostaHttp>;
11
12
  }
@@ -9,37 +9,42 @@ const resposta_http_1 = require("./resposta-http");
9
9
  class ClienteHttp {
10
10
  constructor(urlBase = "", tempoMaximo = 5000, cabecalhos = {}) {
11
11
  this.instanciaAxios = axios_1.default.create({
12
- baseURL: urlBase,
12
+ baseURL: `${urlBase}`,
13
13
  timeout: tempoMaximo,
14
14
  headers: cabecalhos
15
15
  });
16
16
  }
17
17
  async requisicaoGet(sufixoUrl, cabecalhos) {
18
- const respostaAxios = await this.instanciaAxios.get(sufixoUrl, {
18
+ const sufixoUrlResolvido = sufixoUrl.hasOwnProperty("valor") ? sufixoUrl.valor : sufixoUrl;
19
+ const respostaAxios = await this.instanciaAxios.get(`${sufixoUrlResolvido}`, {
19
20
  headers: Object.assign({}, cabecalhos)
20
21
  });
21
22
  return new resposta_http_1.RespostaHttp(respostaAxios.status, respostaAxios.statusText, respostaAxios.data);
22
23
  }
23
24
  async requisicaoPost(sufixoUrl, corpo, cabecalhos) {
24
- const respostaAxios = await this.instanciaAxios.post(sufixoUrl, corpo, {
25
+ const sufixoUrlResolvido = sufixoUrl.hasOwnProperty("valor") ? sufixoUrl.valor : sufixoUrl;
26
+ const respostaAxios = await this.instanciaAxios.post(`${sufixoUrlResolvido}`, corpo, {
25
27
  headers: Object.assign({}, cabecalhos)
26
28
  });
27
29
  return new resposta_http_1.RespostaHttp(respostaAxios.status, respostaAxios.statusText, respostaAxios.data);
28
30
  }
29
31
  async requisicaoPut(sufixoUrl, corpo, cabecalhos) {
30
- const respostaAxios = await this.instanciaAxios.put(sufixoUrl, corpo, {
32
+ const sufixoUrlResolvido = sufixoUrl.hasOwnProperty("valor") ? sufixoUrl.valor : sufixoUrl;
33
+ const respostaAxios = await this.instanciaAxios.put(`${sufixoUrlResolvido}`, corpo, {
31
34
  headers: Object.assign({}, cabecalhos)
32
35
  });
33
36
  return new resposta_http_1.RespostaHttp(respostaAxios.status, respostaAxios.statusText, respostaAxios.data);
34
37
  }
35
38
  async requisicaoDelete(sufixoUrl, cabecalhos) {
36
- const respostaAxios = await this.instanciaAxios.delete(sufixoUrl, {
39
+ const sufixoUrlResolvido = sufixoUrl.hasOwnProperty("valor") ? sufixoUrl.valor : sufixoUrl;
40
+ const respostaAxios = await this.instanciaAxios.delete(`${sufixoUrlResolvido}`, {
37
41
  headers: Object.assign({}, cabecalhos)
38
42
  });
39
43
  return new resposta_http_1.RespostaHttp(respostaAxios.status, respostaAxios.statusText, respostaAxios.data);
40
44
  }
41
45
  async requisicaoPatch(sufixoUrl, corpo, cabecalhos) {
42
- const respostaAxios = await this.instanciaAxios.patch(sufixoUrl, corpo, {
46
+ const sufixoUrlResolvido = sufixoUrl.hasOwnProperty("valor") ? sufixoUrl.valor : sufixoUrl;
47
+ const respostaAxios = await this.instanciaAxios.patch(`${sufixoUrlResolvido}`, corpo, {
43
48
  headers: Object.assign({}, cabecalhos)
44
49
  });
45
50
  return new resposta_http_1.RespostaHttp(respostaAxios.status, respostaAxios.statusText, respostaAxios.data);
@@ -1 +1 @@
1
- {"version":3,"file":"cliente-http.js","sourceRoot":"","sources":["../../fontes/cliente-http.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAoF;AACpF,mDAA+C;AAE/C,MAAa,WAAW;IAGpB,YAAY,UAAkB,EAAE,EAAE,cAAsB,IAAI,EAAE,aAAkB,EAAE;QAC9E,IAAI,CAAC,cAAc,GAAG,eAAK,CAAC,MAAM,CAAC;YAC/B,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,UAAU;SACtB,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,UAAmC;QACtE,MAAM,aAAa,GAA4B,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CACxE,SAAS,EACT;YACI,OAAO,oBACA,UAAU,CAChB;SACJ,CACJ,CAAC;QAEF,OAAO,IAAI,4BAAY,CACnB,aAAa,CAAC,MAAM,EACpB,aAAa,CAAC,UAAU,EACxB,aAAa,CAAC,IAAI,CACrB,CAAC;IACN,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,SAAiB,EAAE,KAAU,EAAE,UAAmC;QACnF,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ACA,UAAU,CAChB;SACJ,CACJ,CAAC;QAEF,OAAO,IAAI,4BAAY,CACnB,aAAa,CAAC,MAAM,EACpB,aAAa,CAAC,UAAU,EACxB,aAAa,CAAC,IAAI,CACrB,CAAC;IACN,CAAC;CACJ;AAvGD,kCAuGC"}
@@ -0,0 +1,4 @@
1
+ export interface ArgumentoInterface {
2
+ nome: string;
3
+ valor: any;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=argumento-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argumento-interface.js","sourceRoot":"","sources":["../../../fontes/interfaces/argumento-interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export * from './argumento-interface';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./argumento-interface"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../fontes/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC"}
package/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.novoClienteHttp = void 0;
17
+ exports.novoClienteHttp = novoClienteHttp;
18
18
  const cliente_http_1 = require("./fontes/cliente-http");
19
19
  /**
20
20
  * Monta o cliente HTTP básico para requisições.
@@ -28,6 +28,5 @@ const cliente_http_1 = require("./fontes/cliente-http");
28
28
  function novoClienteHttp(_, urlBase = "", tempoMaximo = 5000, cabecalhos = {}) {
29
29
  return new cliente_http_1.ClienteHttp(urlBase, tempoMaximo, cabecalhos);
30
30
  }
31
- exports.novoClienteHttp = novoClienteHttp;
32
31
  __exportStar(require("./fontes/resposta-http"), exports);
33
32
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wDAAoD;AAEpD;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,CAAM,EAAE,UAAkB,EAAE,EAAE,cAAsB,IAAI,EAAE,aAAkB,EAAE;IAC1G,OAAO,IAAI,0BAAW,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAC7D,CAAC;AAFD,0CAEC;AAED,yDAAuC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAWA,0CAEC;AAbD,wDAAoD;AAEpD;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,CAAM,EAAE,UAAkB,EAAE,EAAE,cAAsB,IAAI,EAAE,aAAkB,EAAE;IAC1G,OAAO,IAAI,0BAAW,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAC7D,CAAC;AAED,yDAAuC"}
@@ -0,0 +1,3 @@
1
+ import type { Config } from '@jest/types';
2
+ declare const _default: () => Promise<Config.InitialOptions>;
3
+ export default _default;
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = async () => {
4
+ return {
5
+ verbose: true,
6
+ modulePathIgnorePatterns: ['<rootDir>/dist/'],
7
+ preset: 'ts-jest',
8
+ testEnvironment: 'node',
9
+ coverageReporters: ['text', 'text-summary', 'lcov'],
10
+ };
11
+ };
12
+ //# sourceMappingURL=jest.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AAEA,kBAAe,KAAK,IAAoC,EAAE;IACtD,OAAO;QACH,OAAO,EAAE,IAAI;QACb,wBAAwB,EAAE,CAAC,iBAAiB,CAAC;QAC7C,MAAM,EAAE,SAAS;QACjB,eAAe,EAAE,MAAM;QACvB,iBAAiB,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC;KACtD,CAAC;AACN,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designliquido/delegua-http",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Biblioteca para acessos HTTP em Delégua",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,12 @@
15
15
  "axios": "^1.8.4"
16
16
  },
17
17
  "devDependencies": {
18
+ "@types/jest": "^29.5.14",
18
19
  "copyfiles": "^2.4.1",
19
- "rimraf": "^6.0.1"
20
+ "jest": "^29.7.0",
21
+ "rimraf": "^6.0.1",
22
+ "ts-jest": "^29.3.1",
23
+ "ts-node": "^10.9.2",
24
+ "typescript": "^5.8.3"
20
25
  }
21
26
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __1 = require("..");
4
+ describe('Cliente HTTP', () => {
5
+ it('Deve trazer dados com sucesso', async () => {
6
+ const clienteHttp = (0, __1.novoClienteHttp)(undefined, "https://github.com");
7
+ const resultado = await clienteHttp.requisicaoGet({ nome: undefined, valor: "/DesignLiquido/delegua" });
8
+ expect(resultado).toBeTruthy();
9
+ expect(resultado.codigoStatus).toBe(200);
10
+ });
11
+ });
12
+ //# sourceMappingURL=cliente-http.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliente-http.test.js","sourceRoot":"","sources":["../../testes/cliente-http.test.ts"],"names":[],"mappings":";;AAAA,0BAAqC;AAErC,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,WAAW,GAAG,IAAA,mBAAe,EAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QACrE,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,wBAAwB,EAAC,CAAC,CAAC;QACvG,MAAM,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;QAC/B,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}