ofsc-utility 1.0.41 → 1.0.44

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 ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+ - version 1.0.43 with built-in resilience and exponential backoff
11
+ - Add -c flag to skip CHANGELOG updates and auto-update logic
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export * from './types';
13
13
  export { generateAllOnHandInventoryOfAllResources, generateAllOnHandInventoryOfAllResourcesCSV } from './inventory';
14
14
  export { getOAuthToken } from './oauthTokenService';
15
15
  export { downloadWorkZoneCSV } from './workZones';
16
- export { AllResources, downloadAllResourcesCSV, getworkSkillsOfResource } from './resources';
16
+ export { AllResources, downloadAllResourcesCSV, getResourcebyId, getworkSkillsOfResource } from './resources';
17
17
  export { downloadAllInactiveUsers, downloadAllInactiveUsersCSV, downloadAllUsersCSV, generateUsersCollaborationCSV } from './users';
18
18
  export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
19
19
  export { getActivitybyId, getAllActivities } from './activities';
@@ -56,6 +56,7 @@ declare const OfscUtility: {
56
56
  getActivitybyId: any;
57
57
  AllResources: any;
58
58
  getworkSkillsOfResource: any;
59
+ getResource: any;
59
60
  createExcelFile: any;
60
61
  };
61
62
  export default OfscUtility;
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createConfigurationFile = exports.createExcelFile = exports.downloadAllEventsOfLastOneHour = exports.downloadAllEventsOfDLastTwoMinutes = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = exports.getworkSkillsOfResource = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = exports.generateAllOnHandInventoryOfAllResources = exports.WorkZone = exports.Utilities = exports.User = exports.Resource = exports.OauthTokenService = exports.CreateConfigurationFile = exports.InventoryType = exports.Inventory = exports.Events = exports.ActivityInventories = exports.Activity = void 0;
39
+ exports.createConfigurationFile = exports.createExcelFile = exports.downloadAllEventsOfLastOneHour = exports.downloadAllEventsOfDLastTwoMinutes = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = exports.getworkSkillsOfResource = exports.getResourcebyId = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = exports.generateAllOnHandInventoryOfAllResources = exports.WorkZone = exports.Utilities = exports.User = exports.Resource = exports.OauthTokenService = exports.CreateConfigurationFile = exports.InventoryType = exports.Inventory = exports.Events = exports.ActivityInventories = exports.Activity = void 0;
40
40
  // Export all methods grouped by category
41
41
  exports.Activity = __importStar(require("./activities"));
42
42
  exports.ActivityInventories = __importStar(require("./activityInventories"));
@@ -61,6 +61,7 @@ Object.defineProperty(exports, "downloadWorkZoneCSV", { enumerable: true, get: f
61
61
  var resources_1 = require("./resources");
62
62
  Object.defineProperty(exports, "AllResources", { enumerable: true, get: function () { return resources_1.AllResources; } });
63
63
  Object.defineProperty(exports, "downloadAllResourcesCSV", { enumerable: true, get: function () { return resources_1.downloadAllResourcesCSV; } });
64
+ Object.defineProperty(exports, "getResourcebyId", { enumerable: true, get: function () { return resources_1.getResourcebyId; } });
64
65
  Object.defineProperty(exports, "getworkSkillsOfResource", { enumerable: true, get: function () { return resources_1.getworkSkillsOfResource; } });
65
66
  var users_1 = require("./users");
66
67
  Object.defineProperty(exports, "downloadAllInactiveUsers", { enumerable: true, get: function () { return users_1.downloadAllInactiveUsers; } });
@@ -122,6 +123,7 @@ const OfscUtility = {
122
123
  getActivitybyId: require('./activities').getActivitybyId,
123
124
  AllResources: require('./activities').AllResources,
124
125
  getworkSkillsOfResource: require('./resources').getworkSkillsOfResource,
126
+ getResource: require('./resources').getResourcebyId,
125
127
  createExcelFile: require('./utilities').createExcelFile
126
128
  };
127
129
  exports.default = OfscUtility;
@@ -1,6 +1,8 @@
1
+ import { ResourceResponse } from "../types";
1
2
  export declare function downloadAllResourcesCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
2
- export declare function AllResources(clientId: string, clientSecret: string, instanceUrl: string, initialToken?: string): Promise<any[]>;
3
+ export declare function AllResources(clientId: string, clientSecret: string, instanceUrl: string, initialToken?: string): Promise<ResourceResponse[]>;
3
4
  export declare function getworkSkillsOfResource(clientId: string, clientSecret: string, instanceUrl: string, resourceId: number, token?: string): Promise<{
4
5
  token: string;
5
6
  data: any;
6
7
  }>;
8
+ export declare function getResourcebyId(resourceId: string, clientId: string, clientSecret: string, instanceUrl: string, initialToken?: string): Promise<ResourceResponse>;
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.downloadAllResourcesCSV = downloadAllResourcesCSV;
40
40
  exports.AllResources = AllResources;
41
41
  exports.getworkSkillsOfResource = getworkSkillsOfResource;
42
+ exports.getResourcebyId = getResourcebyId;
42
43
  const fs = __importStar(require("fs"));
43
44
  const node_fetch_1 = __importDefault(require("node-fetch"));
44
45
  const index_1 = require("../oauthTokenService/index");
@@ -140,3 +141,11 @@ async function getworkSkillsOfResource(clientId, clientSecret, instanceUrl, reso
140
141
  data: response.data.items
141
142
  };
142
143
  }
144
+ async function getResourcebyId(resourceId, clientId, clientSecret, instanceUrl, initialToken = "") {
145
+ const fetchResources = async (offset, token) => {
146
+ const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resourceId)}?offset=${offset}&limit=100`;
147
+ const res = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
148
+ return res.data;
149
+ };
150
+ return fetchResources(0, initialToken);
151
+ }
@@ -78,7 +78,7 @@ const fetchWithRetry = async (url, clientId, clientSecret, instanceUrl, token, r
78
78
  res = await doFetch(token);
79
79
  }
80
80
  /* ---------- 429: retry with backoff ---------- */
81
- if ((res.status === 429 || res.status === 400) && retries > 0) {
81
+ if ((res.status === 429 || res.status === 502 || res.status === 503 || res.status === 504) && retries > 0) {
82
82
  const retryAfter = res.headers.get("Retry-After");
83
83
  console.log("⚠️ 429 received. Retrying...", retryAfter);
84
84
  const delay = retryAfter ? Number(retryAfter) * 1000 : baseDelay;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsc-utility",
3
- "version": "1.0.41",
3
+ "version": "1.0.44",
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",
@@ -14,16 +14,21 @@
14
14
  "dev": "ts-node src/index.ts"
15
15
  },
16
16
  "keywords": [
17
- "ofs",
18
17
  "oracle",
19
- "Oracle Field Service",
20
- "OFSC"
18
+ "oracle-field-service",
19
+ "oracle-field-service-cloud",
20
+ "ofsc",
21
+ "ofsc-plugin",
22
+ "field-service",
23
+ "oracle-ofsc",
24
+ "oracle-cloud"
21
25
  ],
22
26
  "author": "MOHD AHSHAN DANISH <https://www.linkedin.com/in/mohdahshandanish/>",
23
27
  "license": "MIT",
24
28
  "files": [
25
29
  "dist",
26
30
  "README.md",
31
+ "CHANGELOG.md",
27
32
  "LICENSE"
28
33
  ],
29
34
  "repository": {
package/readme.md CHANGED
@@ -9,10 +9,29 @@ This package exposes grouped API helpers for common OFSC operations, including:
9
9
  - inventory and activity records
10
10
  - metadata file generation
11
11
 
12
+ ### Built-in resilience for OFSC's server errors
13
+
14
+ OFSC's REST API sits behind Oracle's gateway infrastructure, which means calls can occasionally fail with transient errors that have nothing to do with your request — the gateway losing its connection to the backend, a brief service restart, or normal rate limiting under load. This package handles those cases automatically so your integration doesn't fail on a blip that would have succeeded a second later.
15
+
16
+ ### Exponential backoff
17
+
18
+ Retries don't hammer the API at a fixed interval — each attempt waits longer than the last (starting at a small base delay and doubling each time), unless OFSC explicitly tells us how long to wait via Retry-After. This gives Oracle's backend room to recover instead of adding to the load that likely caused the error in the first place.
19
+
20
+ ### Why this matters for OFSC specifically
21
+
22
+ OFSC's gateway is known to return 503s and connection resets during normal operation — not just outages — especially under sustained polling or bulk export workloads (events, activities, inventory).Handling these
23
+ transparently means:
24
+
25
+ - Scheduled jobs don't die on a single flaky response and require manual re-runs
26
+ - Token expiry mid-session is handled without the caller needing to track token lifetimes
27
+ - You get clear, real error messages (with the response body attached) for
28
+ genuine failures, instead of noisy retries on errors that were never going
29
+ to succeed
30
+
12
31
  ## Installation
13
32
 
14
33
  ```bash
15
- npm install ofsc-utility
34
+ npm install ofsc-utility@latest
16
35
  ```
17
36
 
18
37
  ## Getting Started
@@ -452,6 +471,7 @@ Top-level exports include:
452
471
  - `getOAuthToken`
453
472
  - `downloadWorkZoneCSV`
454
473
  - `downloadAllResourcesCSV`
474
+ - `getResource`
455
475
  - `downloadAllUsersCSV`
456
476
  - `downloadAllInactiveUsersCSV`
457
477
  - `generateAllOnHandInventoryOfAllResourcesCSV`