@tec.pet/tecpet-sdk 0.0.230 → 0.0.231

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.
@@ -0,0 +1,14 @@
1
+ import { ApiIntegrationType } from './pa.get-integration-shop-by-login.dto';
2
+ export declare class PaGetIntegrationShopCredentialsResponse {
3
+ shopId: number;
4
+ integrationShopId: number;
5
+ integrationShopType: ApiIntegrationType;
6
+ enabled: boolean;
7
+ externId: string | null;
8
+ /** No Omie, a app_key. */
9
+ login: string | null;
10
+ /** No Omie, a app_secret. */
11
+ token: string | null;
12
+ password: string | null;
13
+ extraConfig: any;
14
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaGetIntegrationShopCredentialsResponse = void 0;
4
+ class PaGetIntegrationShopCredentialsResponse {
5
+ shopId;
6
+ integrationShopId;
7
+ integrationShopType;
8
+ enabled;
9
+ externId;
10
+ /** No Omie, a app_key. */
11
+ login;
12
+ /** No Omie, a app_secret. */
13
+ token;
14
+ password;
15
+ extraConfig;
16
+ }
17
+ exports.PaGetIntegrationShopCredentialsResponse = PaGetIntegrationShopCredentialsResponse;
@@ -2,9 +2,12 @@ export interface PaShopWithIntegrationResponse {
2
2
  id: number;
3
3
  name: string;
4
4
  externId: string;
5
- login: string;
6
- token: string;
7
- password: string;
5
+ /** Não vem na listagem do Omie: ler `getIntegrationShopCredentials` da loja. */
6
+ login?: string;
7
+ /** Não vem na listagem do Omie. */
8
+ token?: string;
9
+ /** Não vem na listagem do Omie. */
10
+ password?: string;
8
11
  extraConfig: any;
9
12
  chainId: string;
10
13
  integrationShopId: number;
@@ -2,3 +2,4 @@ export * from './integrationShop.service';
2
2
  export * from './dto/pa.get-integration-shop-by-login.dto';
3
3
  export * from './dto/pa.get-integration-shop-by-shop-id.dto';
4
4
  export * from './dto/pa.edit-integration-shop.dto';
5
+ export * from './dto/pa.get-integration-shop-credentials.dto';
@@ -18,3 +18,4 @@ __exportStar(require("./integrationShop.service"), exports);
18
18
  __exportStar(require("./dto/pa.get-integration-shop-by-login.dto"), exports);
19
19
  __exportStar(require("./dto/pa.get-integration-shop-by-shop-id.dto"), exports);
20
20
  __exportStar(require("./dto/pa.edit-integration-shop.dto"), exports);
21
+ __exportStar(require("./dto/pa.get-integration-shop-credentials.dto"), exports);
@@ -3,10 +3,16 @@ import { ApiIntegrationType, PaGetIntegrationShopByLoginResponse } from "./dto/p
3
3
  import { PaEditIntegrationShopRequest, PaEditIntegrationShopResponse } from "./dto/pa.edit-integration-shop.dto";
4
4
  import { PaShopWithIntegrationResponse } from "./dto/pa.get-shops-with-integration.dto";
5
5
  import { PaGetIntegrationShopByShopIdResponse } from "./dto/pa.get-integration-shop-by-shop-id.dto";
6
+ import { PaGetIntegrationShopCredentialsResponse } from "./dto/pa.get-integration-shop-credentials.dto";
6
7
  export declare class IntegrationShopService {
7
8
  private readonly api;
8
9
  constructor(api: HttpClient);
9
10
  getIntegrationShopByShopId(shopId: number, integrationType: ApiIntegrationType | string): Promise<PaGetIntegrationShopByShopIdResponse>;
11
+ /**
12
+ * Credenciais da integração de uma loja (login, token, senha, externId, extraConfig). Só o
13
+ * token interno da tecpet tem acesso. O corpo da resposta não vai para o log.
14
+ */
15
+ getIntegrationShopCredentials(shopId: number, integrationType: ApiIntegrationType | string): Promise<PaGetIntegrationShopCredentialsResponse>;
10
16
  getIntegrationShopByLogin(type: ApiIntegrationType | string, login: string): Promise<PaGetIntegrationShopByLoginResponse>;
11
17
  edit(body: PaEditIntegrationShopRequest, shopId: number): Promise<PaEditIntegrationShopResponse>;
12
18
  getShopsWithIntegration(integrationType: string): Promise<PaShopWithIntegrationResponse[]>;
@@ -10,6 +10,14 @@ class IntegrationShopService {
10
10
  const path = `/integrationShop/shop/type/${integrationType}`;
11
11
  return await this.api.get(path, undefined, shopId);
12
12
  }
13
+ /**
14
+ * Credenciais da integração de uma loja (login, token, senha, externId, extraConfig). Só o
15
+ * token interno da tecpet tem acesso. O corpo da resposta não vai para o log.
16
+ */
17
+ async getIntegrationShopCredentials(shopId, integrationType) {
18
+ const path = `/integrationShop/shop/type/${integrationType}/credentials`;
19
+ return await this.api.get(path, undefined, shopId, { sensitive: true });
20
+ }
13
21
  async getIntegrationShopByLogin(type, login) {
14
22
  const path = `/integrationShop/type/${type}/login/${login}`;
15
23
  return await this.api.get(path);
@@ -1,14 +1,22 @@
1
+ /**
2
+ * Opções de uma chamada. `sensitive` tira o corpo da resposta do log (sucesso e erro), para
3
+ * rotas que devolvem credenciais.
4
+ */
5
+ export interface HttpRequestOptions {
6
+ sensitive?: boolean;
7
+ }
1
8
  export declare class HttpClient {
2
9
  private readonly apiUrl;
3
10
  private readonly apiKey?;
4
11
  private readonly client;
5
12
  constructor(apiUrl: string, apiKey?: string | undefined);
6
- get<T>(path: string, payload?: any, shopId?: number): Promise<T>;
13
+ get<T>(path: string, payload?: any, shopId?: number, options?: HttpRequestOptions): Promise<T>;
7
14
  post<T>(path: string, payload?: any, shopId?: number): Promise<T>;
8
15
  put<T>(path: string, payload?: any, shopId?: number): Promise<T>;
9
16
  patch<T>(path: string, payload?: any, shopId?: number): Promise<T>;
10
17
  delete<T>(path: string, shopId?: number): Promise<T>;
11
18
  private headers;
19
+ private isSensitive;
12
20
  private shop;
13
21
  /**
14
22
  * Repassa o corpo cru do erro da API. Sem resposta (timeout, falha de rede) ou com
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HttpClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const stdout_logger_1 = require("../logger/stdout.logger");
9
+ const REDACTED = '[redacted]';
9
10
  class HttpClient {
10
11
  apiUrl;
11
12
  apiKey;
@@ -26,19 +27,21 @@ class HttpClient {
26
27
  return config;
27
28
  });
28
29
  this.client.interceptors.response.use((response) => {
29
- stdout_logger_1.logger.debug('tecpet-sdk', `[HTTP] ${this.shop(response.config.headers)} ← ${response.status} ${response.config.url}`, response?.data);
30
+ const data = this.isSensitive(response.config) ? REDACTED : response?.data;
31
+ stdout_logger_1.logger.debug('tecpet-sdk', `[HTTP] ${this.shop(response.config.headers)} ← ${response.status} ${response.config.url}`, data);
30
32
  return response;
31
33
  }, (error) => {
32
34
  stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error?.config?.headers)} ← Error: ${error.message}`);
33
35
  if (error.response) {
34
- stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error?.config?.headers)} ← Response:`, error?.response?.data);
36
+ const data = this.isSensitive(error?.config) ? REDACTED : error?.response?.data;
37
+ stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error?.config?.headers)} ← Response:`, data);
35
38
  }
36
39
  return Promise.reject(error);
37
40
  });
38
41
  }
39
- async get(path, payload, shopId) {
42
+ async get(path, payload, shopId, options) {
40
43
  try {
41
- const response = await this.client.get(path, { params: payload, headers: this.headers({ shopId }) });
44
+ const response = await this.client.get(path, { params: payload, headers: this.headers({ shopId }), ...(options?.sensitive ? { sensitive: true } : {}) });
42
45
  return response?.data;
43
46
  }
44
47
  catch (error) {
@@ -90,6 +93,9 @@ class HttpClient {
90
93
  }
91
94
  return this.client.defaults.headers.common;
92
95
  }
96
+ isSensitive(config) {
97
+ return config?.sensitive === true;
98
+ }
93
99
  shop(headers) {
94
100
  const shop = headers?.['x-shop']?.toString();
95
101
  return shop ? `shop=${shop}` : '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tec.pet/tecpet-sdk",
3
- "version": "0.0.230",
3
+ "version": "0.0.231",
4
4
  "description": "TecPet SDK for integration with TecPet services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",