contentoh-components-library 21.6.19 → 21.6.20

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/.env.test CHANGED
@@ -72,4 +72,5 @@ SKIP_PREFLIGHT_CHECK=true
72
72
 
73
73
  REACT_APP_ID_AWS=7o2hp8msfl
74
74
  REACT_APP_ENVIRONMENT=test
75
- REACT_APP_REGION=us-east-1
75
+ REACT_APP_REGION=us-east-1
76
+ REACT_APP_VARIANTS_ENDPOINT=https://7o2hp8msfl.execute-api.us-east-1.amazonaws.com/test/variants
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.unwrap = exports.readPayload = exports.ApiError = void 0;
9
+
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createClass"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/classCallCheck"));
13
+
14
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/inherits"));
15
+
16
+ var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createSuper"));
17
+
18
+ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/wrapNativeSuper"));
19
+
20
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
21
+
22
+ /*
23
+ Las lambdas de este API están declaradas con `integration: lambda`, no con
24
+ lambda-proxy. Eso tiene dos consecuencias que se pagan caras si se ignoran:
25
+
26
+ 1. La respuesta llega ENVUELTA: axios entrega { statusCode, headers, body },
27
+ con `body` en texto. Leer `res.data.candidates` da undefined.
28
+ 2. El HTTP siempre es 200, incluso cuando la lambda respondió 400 o 500. Un
29
+ try/catch alrededor de axios NUNCA se dispara por un error de negocio: el
30
+ error viaja dentro del cuerpo y hay que mirar `statusCode` a mano.
31
+
32
+ El repo ya vive con esto —provider-product-edition.context.jsx hace
33
+ JSON.parse(res.data.body)— pero sin un lugar común cada llamada nueva vuelve a
34
+ tropezar. Esto lo centraliza.
35
+ */
36
+ var unwrap = function unwrap(res) {
37
+ var _res$status;
38
+
39
+ var payload = res === null || res === void 0 ? void 0 : res.data;
40
+ var envuelto = payload && (0, _typeof2.default)(payload) === "object" && "statusCode" in payload && "body" in payload;
41
+ if (!envuelto) return {
42
+ status: (_res$status = res === null || res === void 0 ? void 0 : res.status) !== null && _res$status !== void 0 ? _res$status : 200,
43
+ body: payload
44
+ };
45
+ var body = typeof payload.body === "string" ? safeParse(payload.body) : payload.body;
46
+ return {
47
+ status: Number(payload.statusCode),
48
+ body: body
49
+ };
50
+ };
51
+
52
+ exports.unwrap = unwrap;
53
+
54
+ var safeParse = function safeParse(text) {
55
+ try {
56
+ return JSON.parse(text);
57
+ } catch (error) {
58
+ return {
59
+ message: text
60
+ };
61
+ }
62
+ };
63
+ /*
64
+ Error de negocio con el código estable que manda el backend
65
+ (VARIANT_CROSS_COMPANY, VARIANT_ALREADY_LINKED, ...). Se lanza para que el
66
+ llamador use un try/catch normal, aunque el transporte haya dicho 200.
67
+ */
68
+
69
+
70
+ var ApiError = /*#__PURE__*/function (_Error) {
71
+ (0, _inherits2.default)(ApiError, _Error);
72
+
73
+ var _super = (0, _createSuper2.default)(ApiError);
74
+
75
+ function ApiError(code, message) {
76
+ var _this;
77
+
78
+ (0, _classCallCheck2.default)(this, ApiError);
79
+ _this = _super.call(this, message);
80
+ _this.name = "ApiError";
81
+ _this.code = code;
82
+ return _this;
83
+ }
84
+
85
+ return (0, _createClass2.default)(ApiError);
86
+ }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
87
+
88
+ exports.ApiError = ApiError;
89
+
90
+ var readPayload = function readPayload(res) {
91
+ var _unwrap = unwrap(res),
92
+ status = _unwrap.status,
93
+ body = _unwrap.body;
94
+
95
+ if (status >= 400) {
96
+ throw new ApiError(body === null || body === void 0 ? void 0 : body.code, (body === null || body === void 0 ? void 0 : body.message) || "La operación falló.");
97
+ }
98
+
99
+ return body !== null && body !== void 0 ? body : {};
100
+ };
101
+
102
+ exports.readPayload = readPayload;