@griddo/cx 1.75.166 → 1.75.167

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/api/index.js +37 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "1.75.166",
4
+ "version": "1.75.167",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -66,7 +66,7 @@
66
66
  "react-helmet": "^6.0.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@griddo/eslint-config-back": "^1.75.166",
69
+ "@griddo/eslint-config-back": "^1.75.167",
70
70
  "eslint": "^7.5.0",
71
71
  "eslint-plugin-node": "^11.1.0",
72
72
  "eslint-plugin-react": "7.14.3",
@@ -98,5 +98,5 @@
98
98
  "publishConfig": {
99
99
  "access": "public"
100
100
  },
101
- "gitHead": "a23454c1d953a61ec07b57ea3568d47546acccd1"
101
+ "gitHead": "51cf9accd51cbd420aef5a667093e04f5e31d277"
102
102
  }
package/src/api/index.js CHANGED
@@ -12,11 +12,14 @@ const {
12
12
  const getApi = async (endpoint, body, cached = false, attempt = 0) => {
13
13
  const cacheOptions = { endpoint, body, cached };
14
14
  const starts = new Date();
15
+
15
16
  if (cached) {
16
17
  const cachedResponse = getCache(cacheOptions);
17
18
  console.log(`API CALL CACHED: GET ${endpoint} ${new Date() - starts} ms`);
19
+
18
20
  if (cachedResponse) return cachedResponse;
19
21
  }
22
+
20
23
  try {
21
24
  const { data } = await axios({
22
25
  url: endpoint,
@@ -26,12 +29,15 @@ const getApi = async (endpoint, body, cached = false, attempt = 0) => {
26
29
  });
27
30
  console.log(`API CALL ENDS: GET ${endpoint} ${new Date() - starts} ms`);
28
31
  saveCache(cacheOptions, data);
32
+
29
33
  return data;
30
34
  } catch (e) {
31
35
  showApiError(e, { endpoint, body, attempt });
36
+
32
37
  if (attempt < parseInt(RETRY_ATTEMPTS)) {
33
38
  console.log('WAITING FOR RETRY: GET', endpoint);
34
39
  await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
40
+
35
41
  return getApi(endpoint, body, cached, attempt + 1);
36
42
  }
37
43
  }
@@ -40,11 +46,14 @@ const getApi = async (endpoint, body, cached = false, attempt = 0) => {
40
46
  const putApi = async (endpoint, body, cached = false, attempt = 0) => {
41
47
  const cacheOptions = { endpoint, body, cached };
42
48
  const starts = new Date();
49
+
43
50
  if (cached) {
44
51
  const cachedResponse = getCache(cacheOptions);
45
52
  console.log(`API CALL CACHED: PUT ${endpoint} ${new Date() - starts} ms`);
53
+
46
54
  if (cachedResponse) return cachedResponse;
47
55
  }
56
+
48
57
  try {
49
58
  const { data } = await axios({
50
59
  url: endpoint,
@@ -54,12 +63,15 @@ const putApi = async (endpoint, body, cached = false, attempt = 0) => {
54
63
  });
55
64
  console.log(`API CALL ENDS: PUT ${endpoint} ${new Date() - starts} ms`);
56
65
  saveCache(cacheOptions, data);
66
+
57
67
  return data;
58
68
  } catch (e) {
59
69
  showApiError(e, { endpoint, body, attempt });
70
+
60
71
  if (attempt < parseInt(RETRY_ATTEMPTS)) {
61
72
  console.log('WAITING FOR RETRY: PUT', endpoint);
62
73
  await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
74
+
63
75
  return putApi(endpoint, body, cached, attempt + 1);
64
76
  }
65
77
  }
@@ -68,11 +80,24 @@ const putApi = async (endpoint, body, cached = false, attempt = 0) => {
68
80
  const postApi = async (endpoint, body, headers, cached, attempt = 0) => {
69
81
  const cacheOptions = { endpoint, body, headers, cached };
70
82
  const starts = new Date();
83
+ const distributorBodyParams = endpoint.endsWith('/distributor')
84
+ ? `# Distributor body: ${JSON.stringify(body)} - lang: ${JSON.stringify(
85
+ headers?.lang
86
+ )}`
87
+ : '';
88
+
71
89
  if (cached) {
72
90
  const cachedResponse = getCache(cacheOptions);
73
- console.log(`API CALL CACHED: POST ${endpoint} ${new Date() - starts} ms`);
91
+
92
+ console.log(
93
+ `API CALL CACHED: POST ${endpoint} ${
94
+ new Date() - starts
95
+ } ms ${distributorBodyParams}`
96
+ );
97
+
74
98
  if (cachedResponse) return cachedResponse;
75
99
  }
100
+
76
101
  try {
77
102
  const { data } = await axios({
78
103
  url: endpoint,
@@ -80,14 +105,22 @@ const postApi = async (endpoint, body, headers, cached, attempt = 0) => {
80
105
  headers: { ...headers, ...auth.headers },
81
106
  data: body,
82
107
  });
83
- console.log(`API CALL ENDS: POST ${endpoint} ${new Date() - starts} ms`);
108
+
109
+ console.log(
110
+ `API CALL ENDS: POST ${endpoint} ${
111
+ new Date() - starts
112
+ } ms ${distributorBodyParams}`
113
+ );
84
114
  saveCache(cacheOptions, data);
115
+
85
116
  return data;
86
117
  } catch (e) {
87
118
  showApiError(e, { endpoint, body, headers, attempt });
119
+
88
120
  if (attempt < parseInt(RETRY_ATTEMPTS)) {
89
121
  console.log('WAITING FOR RETRY: POST', endpoint);
90
122
  await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
123
+
91
124
  return postApi(endpoint, body, headers, cached, attempt + 1);
92
125
  }
93
126
  }
@@ -97,6 +130,7 @@ const showApiError = (e, callInfo = {}) => {
97
130
  const { response, message, stack } = e;
98
131
  const { status, statusText, data } = response || {};
99
132
  const callInfoArray = [];
133
+
100
134
  for (const item of Object.keys(callInfo)) {
101
135
  callInfoArray.push(
102
136
  `- ${item}: ${
@@ -106,6 +140,7 @@ const showApiError = (e, callInfo = {}) => {
106
140
  }`
107
141
  );
108
142
  }
143
+
109
144
  console.error(
110
145
  `===========================\n*** CALL INFO ***\n${callInfoArray.join(
111
146
  '\n'