sysone-api-mapper 1.0.180 → 1.0.182

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.
package/dist/index.d.ts CHANGED
@@ -4,5 +4,6 @@ import axiosInstance from "./axiosInstance";
4
4
  import { configureApiMapper, apiMapper } from "./src/mapper/Mapper";
5
5
  import { ApiContext, useApi } from "./src/contexts/apiContext";
6
6
  import { createApiAdapter } from "./src/adapters/createApiAdapter";
7
- export { apiCall, apiMapper, endpoints, axiosInstance, configureApiMapper, ApiContext, useApi, createApiAdapter, };
7
+ import { ApiError } from "./src/mapper/errors/ApiError";
8
+ export { apiCall, apiMapper, endpoints, axiosInstance, configureApiMapper, ApiContext, useApi, createApiAdapter, ApiError, };
8
9
  export type { Api } from './src/adapters/createApiAdapter';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createApiAdapter = exports.useApi = exports.ApiContext = exports.configureApiMapper = exports.axiosInstance = exports.endpoints = exports.apiMapper = exports.apiCall = void 0;
6
+ exports.ApiError = exports.createApiAdapter = exports.useApi = exports.ApiContext = exports.configureApiMapper = exports.axiosInstance = exports.endpoints = exports.apiMapper = exports.apiCall = void 0;
7
7
  const services_1 = require("./services");
8
8
  Object.defineProperty(exports, "apiCall", { enumerable: true, get: function () { return services_1.apiCall; } });
9
9
  const servicesData_1 = require("./servicesData");
@@ -18,3 +18,5 @@ Object.defineProperty(exports, "ApiContext", { enumerable: true, get: function (
18
18
  Object.defineProperty(exports, "useApi", { enumerable: true, get: function () { return apiContext_1.useApi; } });
19
19
  const createApiAdapter_1 = require("./src/adapters/createApiAdapter");
20
20
  Object.defineProperty(exports, "createApiAdapter", { enumerable: true, get: function () { return createApiAdapter_1.createApiAdapter; } });
21
+ const ApiError_1 = require("./src/mapper/errors/ApiError");
22
+ Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return ApiError_1.ApiError; } });
@@ -13,7 +13,7 @@ export interface Api {
13
13
  getGenders: () => Promise<any>;
14
14
  getMaritalStatus: () => Promise<any>;
15
15
  getActivity: () => Promise<any>;
16
- getIdentificationTypes: (country: string) => Promise<any>;
16
+ getIdentificationTypes: (personType: string, country: string) => Promise<any>;
17
17
  getPaymentMethodsByPartyCode: (partyCode: string) => Promise<any>;
18
18
  updatePaymentMethodsByPartyCode: (partyCode: string, data: any) => Promise<any>;
19
19
  updatePerson: (partyCode: string, data: any) => Promise<any>;
@@ -6,7 +6,7 @@ export function partyAdapter(tenant: any): {
6
6
  getGenders: () => Promise<any>;
7
7
  getMaritalStatus: () => Promise<any>;
8
8
  getActivity: () => Promise<any>;
9
- getIdentificationTypes: (countryCode: any) => Promise<any>;
9
+ getIdentificationTypes: (personType: any, countryCode: any) => Promise<any>;
10
10
  getPaymentMethodsByPartyCode: (partyCode: any) => Promise<any>;
11
11
  updatePaymentMethodsByPartyCode: (partyCode: any, data: any) => Promise<any>;
12
12
  updatePerson: (partyCode: any, data: any) => Promise<any>;
@@ -10,7 +10,7 @@ const partyAdapter = (tenant) => ({
10
10
  getGenders: () => (0, Mapper_1.apiMapper)("GET_GENDERS", tenant),
11
11
  getMaritalStatus: () => (0, Mapper_1.apiMapper)("GET_MARITAL_STATUS", tenant),
12
12
  getActivity: () => (0, Mapper_1.apiMapper)("GET_ACTIVITY", tenant),
13
- getIdentificationTypes: (countryCode) => (0, Mapper_1.apiMapper)("GET_IDENTIFICATION_TYPES", tenant, [countryCode]),
13
+ getIdentificationTypes: (personType, countryCode) => (0, Mapper_1.apiMapper)("GET_IDENTIFICATION_TYPES", tenant, [personType, countryCode]),
14
14
  getPaymentMethodsByPartyCode: (partyCode) => (0, Mapper_1.apiMapper)("GET_PAYMENT_METHODS_BY_PARTY_CODE", tenant, [partyCode]),
15
15
  updatePaymentMethodsByPartyCode: (partyCode, data) => (0, Mapper_1.apiMapper)("PUT_PAYMENT_METHODS_BY_PARTY_CODE", tenant, [partyCode], data),
16
16
  updatePerson: (partyCode, data) => (0, Mapper_1.apiMapper)("PUT_PERSON", tenant, [partyCode], data),
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.apiMapper = exports.configureApiMapper = void 0;
7
7
  const axiosInstance_1 = __importDefault(require("../../axiosInstance"));
8
8
  const endpointsConfig_1 = require("./endpointsConfig");
9
+ const ApiError_1 = require("./errors/ApiError");
9
10
  let apiConfig = null;
10
11
  const configureApiMapper = (config) => {
11
12
  apiConfig = {
@@ -61,55 +62,60 @@ const apiMapper = async (endpointCode, tenant, routeParams, params = null, addit
61
62
  };
62
63
  const url = getUrl(endpointData.url, routeParams);
63
64
  /* -------- Request -------- */
64
- switch (endpointData.method) {
65
- case endpointsConfig_1.methods.GET: {
66
- const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
67
- const response = await axiosInstance_1.default.get(url, {
68
- ...axiosConfig,
69
- params: mappedParams,
70
- responseType,
71
- headers: {
72
- ...axiosConfig.headers,
73
- ...requestHeaders,
74
- },
75
- ...otherOptions,
76
- });
77
- return endpointData.responseMapper(response);
65
+ try {
66
+ switch (endpointData.method) {
67
+ case endpointsConfig_1.methods.GET: {
68
+ const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
69
+ const response = await axiosInstance_1.default.get(url, {
70
+ ...axiosConfig,
71
+ params: mappedParams,
72
+ responseType,
73
+ headers: {
74
+ ...axiosConfig.headers,
75
+ ...requestHeaders,
76
+ },
77
+ ...otherOptions,
78
+ });
79
+ return endpointData.responseMapper(response);
80
+ }
81
+ case endpointsConfig_1.methods.POST: {
82
+ const { mappedPostParams, mappedBody, headers: requestHeaders } = endpointData.requestMapper(params);
83
+ const response = await axiosInstance_1.default.post(url, mappedBody, {
84
+ ...axiosConfig,
85
+ params: mappedPostParams,
86
+ headers: {
87
+ ...axiosConfig.headers,
88
+ ...requestHeaders,
89
+ },
90
+ });
91
+ return endpointData.responseMapper(response.data);
92
+ }
93
+ case endpointsConfig_1.methods.PUT: {
94
+ const { mappedParams, mappedBody, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
95
+ const response = await axiosInstance_1.default.put(url, mappedBody, {
96
+ ...axiosConfig,
97
+ params: mappedParams,
98
+ headers: {
99
+ ...axiosConfig.headers,
100
+ ...requestHeaders,
101
+ },
102
+ ...otherOptions,
103
+ });
104
+ return endpointData.responseMapper(response);
105
+ }
106
+ case endpointsConfig_1.methods.DELETE: {
107
+ const response = await axiosInstance_1.default.delete(url, {
108
+ ...axiosConfig,
109
+ data: params,
110
+ });
111
+ return endpointData.responseMapper(response.data);
112
+ }
113
+ default:
114
+ throw new Error("HTTP method not supported");
78
115
  }
79
- case endpointsConfig_1.methods.POST: {
80
- const { mappedPostParams, mappedBody, headers: requestHeaders } = endpointData.requestMapper(params);
81
- const response = await axiosInstance_1.default.post(url, mappedBody, {
82
- ...axiosConfig,
83
- params: mappedPostParams,
84
- headers: {
85
- ...axiosConfig.headers,
86
- ...requestHeaders,
87
- },
88
- });
89
- return endpointData.responseMapper(response.data);
90
- }
91
- case endpointsConfig_1.methods.PUT: {
92
- const { mappedParams, mappedBody, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
93
- const response = await axiosInstance_1.default.put(url, mappedBody, {
94
- ...axiosConfig,
95
- params: mappedParams,
96
- headers: {
97
- ...axiosConfig.headers,
98
- ...requestHeaders,
99
- },
100
- ...otherOptions,
101
- });
102
- return endpointData.responseMapper(response);
103
- }
104
- case endpointsConfig_1.methods.DELETE: {
105
- const response = await axiosInstance_1.default.delete(url, {
106
- ...axiosConfig,
107
- data: params,
108
- });
109
- return endpointData.responseMapper(response.data);
110
- }
111
- default:
112
- throw new Error("HTTP method not supported");
116
+ }
117
+ catch (error) {
118
+ throw new ApiError_1.ApiError(error);
113
119
  }
114
120
  };
115
121
  exports.apiMapper = apiMapper;
@@ -213,7 +213,7 @@ const partyModule = {
213
213
  },
214
214
  GET_IDENTIFICATION_TYPES: {
215
215
  default: {
216
- url: 'party/v1/identification-types',
216
+ url: 'party/v1/identification-types?party-type-code={0}&country-code={1}',
217
217
  method: exports.methods.GET,
218
218
  source: 'https://apidoc.sysone.com/party/v1/open-api.html#/paths/~1v1~1identification-types/get',
219
219
  requestMapper: (request) => ({ mappedParams: request }),
@@ -0,0 +1,9 @@
1
+ export class ApiError extends Error {
2
+ constructor(originalError: any);
3
+ status: any;
4
+ data: any;
5
+ errors: any;
6
+ response: any;
7
+ originalError: any;
8
+ isApiError: boolean;
9
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiError = void 0;
4
+ class ApiError extends Error {
5
+ constructor(originalError) {
6
+ var _a, _b, _c, _d, _e, _f;
7
+ const apiMessage = ((_b = (_a = originalError === null || originalError === void 0 ? void 0 : originalError.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message)
8
+ || (originalError === null || originalError === void 0 ? void 0 : originalError.message)
9
+ || 'Unknown API error';
10
+ super(apiMessage);
11
+ this.name = 'ApiError';
12
+ this.status = ((_c = originalError === null || originalError === void 0 ? void 0 : originalError.response) === null || _c === void 0 ? void 0 : _c.status) || null;
13
+ this.data = ((_d = originalError === null || originalError === void 0 ? void 0 : originalError.response) === null || _d === void 0 ? void 0 : _d.data) || null;
14
+ this.errors = ((_f = (_e = originalError === null || originalError === void 0 ? void 0 : originalError.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.errorMessages) || [];
15
+ this.response = (originalError === null || originalError === void 0 ? void 0 : originalError.response) || null;
16
+ this.originalError = originalError;
17
+ this.isApiError = true;
18
+ }
19
+ }
20
+ exports.ApiError = ApiError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sysone-api-mapper",
3
- "version": "1.0.180",
3
+ "version": "1.0.182",
4
4
  "description": "Paquete mapper para portal de productores",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",