ofsc-utility 1.0.44 → 1.0.45

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/CHANGELOG.md CHANGED
@@ -7,5 +7,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
7
7
  ## [Unreleased]
8
8
 
9
9
  ### Added
10
+ - release v1.0.44 with getResource function and updated keywords
10
11
  - version 1.0.43 with built-in resilience and exponential backoff
11
12
  - Add -c flag to skip CHANGELOG updates and auto-update logic
@@ -68,28 +68,35 @@ const fetchWithRetry = async (url, clientId, clientSecret, instanceUrl, token, r
68
68
  }
69
69
  });
70
70
  };
71
- console.log(`➡️ Fetching ${url}`);
71
+ console.log(`Fetching ${url}`);
72
72
  // Try with the current token
73
73
  let res = await doFetch(token);
74
74
  /* ---------- 401: refresh token ONCE per call ---------- */
75
75
  if (res.status === 401) {
76
- console.warn("⚠️ Token expired — renewing token…");
76
+ console.warn("Token expired — renewing token…");
77
77
  token = await (0, oauthTokenService_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
78
78
  res = await doFetch(token);
79
79
  }
80
- /* ---------- 429: retry with backoff ---------- */
81
- if ((res.status === 429 || res.status === 502 || res.status === 503 || res.status === 504) && retries > 0) {
80
+ const responseText = await res.text();
81
+ const isNoRouteToHost = res.status === 400 &&
82
+ responseText.includes("NoRouteToHostException");
83
+ const isRetryableStatus = res.status === 429 ||
84
+ res.status === 502 ||
85
+ res.status === 503 ||
86
+ res.status === 504;
87
+ /* ---------- retry with backoff ---------- */
88
+ if ((isRetryableStatus || isNoRouteToHost) && retries > 0) {
82
89
  const retryAfter = res.headers.get("Retry-After");
83
- console.log("⚠️ 429 received. Retrying...", retryAfter);
90
+ console.log("Retrying...", retryAfter);
84
91
  const delay = retryAfter ? Number(retryAfter) * 1000 : baseDelay;
85
- console.warn(`⚠️ 429 received. Retrying in ${delay}ms... (${retries} left)`);
92
+ console.warn(`Retrying in ${delay}ms... (${retries} left)`);
86
93
  await new Promise(r => setTimeout(r, delay));
87
94
  return (0, exports.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token, retries - 1, baseDelay * 2);
88
95
  }
89
96
  // If still not OK → fail
90
97
  if (!res.ok) {
91
98
  const body = await res.text();
92
- throw new Error(`❌ Request failed: ${res.status} ${res.statusText}\n${body}`);
99
+ throw new Error(`Request failed: ${res.status} ${res.statusText}\n${body}`);
93
100
  }
94
101
  // Return parsed JSON + latest token
95
102
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsc-utility",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "TypeScript helpers for Oracle Field Service Cloud (OFSC): events, resources, inventories, metadata and CSV/Excel utilities.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",