@oondemand/oon-core-back 0.3.64 → 0.3.65

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oondemand/oon-core-back",
3
- "version": "0.3.64",
3
+ "version": "0.3.65",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oondemand/oon-platform.git",
@@ -95,6 +95,22 @@ function responseError(body, statusCode) {
95
95
  });
96
96
  }
97
97
 
98
+ function normalizedStringList(value) {
99
+ const values = Array.isArray(value) ? value : value === undefined || value === null ? [] : [value];
100
+ return values.map((item) => String(item).trim()).filter(Boolean);
101
+ }
102
+
103
+ function isConfiguredEmptyResult(callDefinition = {}, body = {}) {
104
+ const code = String(body?.faultcode ?? body?.code ?? body?.codigo_status ?? "").trim();
105
+ const description = String(
106
+ body?.faultstring ?? body?.description ?? body?.descricao_status ?? "",
107
+ ).trim();
108
+ const codes = normalizedStringList(callDefinition.emptyResultFaultCodes);
109
+ const messages = normalizedStringList(callDefinition.emptyResultMessages);
110
+ return (code && codes.includes(code))
111
+ || (description && messages.some((message) => description.includes(message)));
112
+ }
113
+
98
114
  function retryableTransportError(error) {
99
115
  const statusCode = Number(error?.response?.status || error?.statusCode || 0);
100
116
  return RETRYABLE_HTTP.has(statusCode)
@@ -166,9 +182,10 @@ function createOmieClient(options = {}) {
166
182
  app_secret: appSecret,
167
183
  param: Array.isArray(resolvedParam) ? resolvedParam : [resolvedParam],
168
184
  };
185
+ const callMaxAttempts = Math.max(1, Number(callDefinition.maxAttempts ?? maxAttempts));
169
186
  let lastError;
170
187
 
171
- for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
188
+ for (let attempt = 1; attempt <= callMaxAttempts; attempt += 1) {
172
189
  const startedAt = Date.now();
173
190
  const trace = {
174
191
  endpoint: callDefinition.endpoint,
@@ -185,14 +202,18 @@ function createOmieClient(options = {}) {
185
202
  });
186
203
  const status = Number(response?.status || 200);
187
204
  const data = response?.data ?? {};
205
+ const emptyResult = isConfiguredEmptyResult(callDefinition, data);
188
206
  trace.httpStatus = status;
189
207
  trace.response = sanitizeIntegrationValue(data);
190
208
  trace.durationMs = Date.now() - startedAt;
191
- const normalized = responseError(data, status);
192
- if (normalized) throw normalized;
209
+ trace.emptyResult = emptyResult;
210
+ if (!emptyResult) {
211
+ const normalized = responseError(data, status);
212
+ if (normalized) throw normalized;
213
+ }
193
214
  trace.status = "success";
194
215
  context.recordRequest?.(trace);
195
- return { data, trace };
216
+ return { data, trace, emptyResult };
196
217
  } catch (error) {
197
218
  const normalized = error instanceof OmieApiError
198
219
  ? error
@@ -209,7 +230,7 @@ function createOmieClient(options = {}) {
209
230
  context.recordRequest?.(trace);
210
231
  normalized.trace = trace;
211
232
  lastError = normalized;
212
- if (!normalized.retryable || attempt >= maxAttempts) throw normalized;
233
+ if (!normalized.retryable || attempt >= callMaxAttempts) throw normalized;
213
234
  const delay = Math.min(5_000, retryInitialMs * (2 ** (attempt - 1)));
214
235
  await wait(delay);
215
236
  }
@@ -253,8 +274,9 @@ module.exports = {
253
274
  OmieApiError,
254
275
  createOmieClient,
255
276
  getPath,
277
+ isConfiguredEmptyResult,
256
278
  normalizeEndpoint,
257
279
  resolveCallParam,
258
280
  resolveTemplate,
259
281
  responseError,
260
- };
282
+ };