ofsc-utility 1.0.32 → 1.0.34

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/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export * as User from './users';
10
10
  export * as Utilities from './utilities';
11
11
  export * as WorkZone from './workZones';
12
12
  export * from './types';
13
- export { generateAllOnHandInventoryOfAllResourcesCSV } from './inventory';
13
+ export { generateAllOnHandInventoryOfAllResources, generateAllOnHandInventoryOfAllResourcesCSV } from './inventory';
14
14
  export { getOAuthToken } from './oauthTokenService';
15
15
  export { downloadWorkZoneCSV } from './workZones';
16
16
  export { AllResources, downloadAllResourcesCSV, getworkSkillsOfResource } from './resources';
@@ -18,7 +18,7 @@ export { downloadAllUsersCSV, generateUsersCollaborationCSV } from './users';
18
18
  export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
19
19
  export { getActivitybyId, getAllActivities } from './activities';
20
20
  export { createActivityCustomerInventories, getActivityCustomerInventories } from './activityInventories';
21
- export { downloadAllEventsOfDay, downloadAllEventsOfDayCSV, downloadAllEventsOfLastOneHour } from './events';
21
+ export { downloadAllEventsOfDay, downloadAllEventsOfDayCSV, downloadAllEventsOfDLastTwoMinutes, downloadAllEventsOfLastOneHour } from './events';
22
22
  export { createExcelFile } from './utilities';
23
23
  export { createConfigurationFile } from './metadata';
24
24
  declare const 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.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.getworkSkillsOfResource = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = 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.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;
40
40
  // Export all methods grouped by category
41
41
  exports.Activity = __importStar(require("./activities"));
42
42
  exports.ActivityInventories = __importStar(require("./activityInventories"));
@@ -52,6 +52,7 @@ exports.WorkZone = __importStar(require("./workZones"));
52
52
  // Export types
53
53
  __exportStar(require("./types"), exports);
54
54
  var inventory_1 = require("./inventory");
55
+ Object.defineProperty(exports, "generateAllOnHandInventoryOfAllResources", { enumerable: true, get: function () { return inventory_1.generateAllOnHandInventoryOfAllResources; } });
55
56
  Object.defineProperty(exports, "generateAllOnHandInventoryOfAllResourcesCSV", { enumerable: true, get: function () { return inventory_1.generateAllOnHandInventoryOfAllResourcesCSV; } });
56
57
  var oauthTokenService_1 = require("./oauthTokenService");
57
58
  Object.defineProperty(exports, "getOAuthToken", { enumerable: true, get: function () { return oauthTokenService_1.getOAuthToken; } });
@@ -77,6 +78,7 @@ Object.defineProperty(exports, "getActivityCustomerInventories", { enumerable: t
77
78
  var events_1 = require("./events");
78
79
  Object.defineProperty(exports, "downloadAllEventsOfDay", { enumerable: true, get: function () { return events_1.downloadAllEventsOfDay; } });
79
80
  Object.defineProperty(exports, "downloadAllEventsOfDayCSV", { enumerable: true, get: function () { return events_1.downloadAllEventsOfDayCSV; } });
81
+ Object.defineProperty(exports, "downloadAllEventsOfDLastTwoMinutes", { enumerable: true, get: function () { return events_1.downloadAllEventsOfDLastTwoMinutes; } });
80
82
  Object.defineProperty(exports, "downloadAllEventsOfLastOneHour", { enumerable: true, get: function () { return events_1.downloadAllEventsOfLastOneHour; } });
81
83
  var utilities_1 = require("./utilities");
82
84
  Object.defineProperty(exports, "createExcelFile", { enumerable: true, get: function () { return utilities_1.createExcelFile; } });
@@ -1 +1,5 @@
1
1
  export declare function generateAllOnHandInventoryOfAllResourcesCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
2
+ export declare function generateAllOnHandInventoryOfAllResources(clientId: string, clientSecret: string, instanceUrl: string): Promise<{
3
+ data: any[];
4
+ props: string[];
5
+ }>;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateAllOnHandInventoryOfAllResourcesCSV = generateAllOnHandInventoryOfAllResourcesCSV;
7
+ exports.generateAllOnHandInventoryOfAllResources = generateAllOnHandInventoryOfAllResources;
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const utilities_1 = require("../utilities");
9
10
  async function generateAllOnHandInventoryOfAllResourcesCSV(clientId, clientSecret, instanceUrl) {
@@ -77,3 +78,79 @@ async function generateAllOnHandInventoryOfAllResourcesCSV(clientId, clientSecre
77
78
  (0, utilities_1.saveCsv)(rows, filename);
78
79
  console.log(`📁 CSV saved: ${fullPath}`);
79
80
  }
81
+ async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret, instanceUrl) {
82
+ let offset = 0;
83
+ const limit = 100;
84
+ const allResources = [];
85
+ let token = "";
86
+ console.log("🚀 Starting all Resources Inventories export...");
87
+ console.log("--------------------------------------------------");
88
+ while (true) {
89
+ const resourcesUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/?offset=${offset}&limit=${limit}`;
90
+ console.log(`➡️ Fetching resources offset=${offset}`);
91
+ const res = await (0, utilities_1.fetchWithRetry)(resourcesUrl, clientId, clientSecret, instanceUrl, token);
92
+ token = res.token;
93
+ const data = res.data;
94
+ if (!data?.items?.length) {
95
+ console.warn("⚠ No resource items returned. Breaking.");
96
+ break;
97
+ }
98
+ allResources.push(...data.items);
99
+ console.log(` ✔ Received ${data.items.length} resources (Total: ${allResources.length})`);
100
+ if (offset + limit >= data.totalResults)
101
+ break;
102
+ offset += limit;
103
+ }
104
+ console.log("--------------------------------------------------");
105
+ console.log(`Total resources to process: ${allResources.length}`);
106
+ console.log("--------------------------------------------------");
107
+ // 2. Fetch on hand inventories for each resource
108
+ const rows = [];
109
+ for (const [index, resource] of allResources.entries()) {
110
+ console.log(`${index} 👤 Fetching Inventories for ${resource.resourceId}`);
111
+ if (resource.status !== "active") {
112
+ console.log(` ⚠ Skipping inactive resource ${resource.resourceId}`);
113
+ continue;
114
+ }
115
+ offset = 0;
116
+ while (true) {
117
+ const invUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resource.resourceId)}/inventories/?offset=${offset}&limit=${limit}`;
118
+ try {
119
+ const res = await (0, utilities_1.fetchWithRetry)(invUrl, clientId, clientSecret, instanceUrl, token);
120
+ token = res.token;
121
+ const itemsData = res.data;
122
+ const items = itemsData?.items ?? [];
123
+ if (!items || items.length === 0) {
124
+ console.log(` ⚠ No Inventories found for ${resource.resourceId}`);
125
+ break;
126
+ }
127
+ for (const inv of items) {
128
+ delete inv.links;
129
+ delete inv.status;
130
+ rows.push({ resourceName: resource.name, resourceType: resource.resourceType, resourceTimeZone: resource.timeZoneIANA, ...inv, });
131
+ }
132
+ console.log(` ✔ Found ${items.length} Inventories`);
133
+ if (offset + limit >= itemsData.totalResults)
134
+ break;
135
+ offset += limit;
136
+ }
137
+ catch (err) {
138
+ console.error(`❌ Error fetching Inventories for ${resource.resourceId}:`, err);
139
+ console.log(` ⚠ Skipping invUrl ${invUrl}`);
140
+ }
141
+ }
142
+ }
143
+ console.log("--------------------------------------------------");
144
+ console.log(`Total rows: ${rows.length}`);
145
+ console.log("--------------------------------------------------");
146
+ const props = [...rows.reduce((set, row) => {
147
+ if (row && typeof row === "object") {
148
+ Object.keys(row).forEach((key) => set.add(key));
149
+ }
150
+ return set;
151
+ }, new Set())];
152
+ return {
153
+ data: rows,
154
+ props,
155
+ };
156
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ofsc-utility",
3
- "version": "1.0.32",
4
- "description": "A wrapper for Oracle Field Service REST API",
3
+ "version": "1.0.34",
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",
7
7
  "scripts": {
@@ -16,9 +16,10 @@
16
16
  "keywords": [
17
17
  "ofs",
18
18
  "oracle",
19
- "getOAuthToken"
19
+ "Oracle Field Service",
20
+ "OFSC"
20
21
  ],
21
- "author": "MOHD AHSHAN DANISH <mailtodanish@gmail.com>",
22
+ "author": "MOHD AHSHAN DANISH <https://www.linkedin.com/in/mohdahshandanish/>",
22
23
  "license": "MIT",
23
24
  "files": [
24
25
  "dist",
@@ -27,8 +28,12 @@
27
28
  ],
28
29
  "repository": {
29
30
  "type": "git",
30
- "url": "https://github.com/mailtodanish/ofsc-utility"
31
+ "url": "git+https://github.com/mailtodanish/ofsc-utility.git"
31
32
  },
33
+ "bugs": {
34
+ "url": "https://github.com/mailtodanish/ofsc-utility/issues"
35
+ },
36
+ "homepage": "https://github.com/mailtodanish/ofsc-utility#readme",
32
37
  "devDependencies": {
33
38
  "@rollup/plugin-commonjs": "^29.0.0",
34
39
  "@rollup/plugin-node-resolve": "^16.0.3",
package/readme.md CHANGED
@@ -144,6 +144,52 @@ await ofs.downloadAllUsersCSV(
144
144
  );
145
145
  ```
146
146
 
147
+ ### Resource related methods
148
+
149
+ ```js
150
+ await ofs.generateAllOnHandInventoryOfAllResourcesCSV(
151
+ process.env.CLIENT_ID,
152
+ process.env.CLIENT_SECRET,
153
+ process.env.INSTANCE_NAME,
154
+ );
155
+ ```
156
+
157
+ This helper fetches all active resources and writes their on-hand inventory rows to a CSV file.
158
+
159
+ ```js
160
+ const inventoryResult = await ofs.generateAllOnHandInventoryOfAllResources(
161
+ process.env.CLIENT_ID,
162
+ process.env.CLIENT_SECRET,
163
+ process.env.INSTANCE_NAME,
164
+ );
165
+
166
+ console.log(`Loaded ${inventoryResult.data.length} inventory rows`);
167
+ console.log("Available table columns:", inventoryResult.props);
168
+ ```
169
+
170
+ This method fetches active resources and returns an object containing:
171
+
172
+ - `data`: an array of inventory row objects
173
+ - `props`: an array of unique keys found across all row objects
174
+
175
+ The `props` array can be used as your dynamic table columns. For example:
176
+
177
+ ```js
178
+ const columns = inventoryResult.props;
179
+ const rows = inventoryResult.data;
180
+
181
+ columns.forEach((col) => {
182
+ console.log(`Column: ${col}`);
183
+ });
184
+
185
+ rows.forEach((row) => {
186
+ const cells = columns.map((col) => row[col]);
187
+ console.log(cells);
188
+ });
189
+ ```
190
+
191
+ This gives you a dynamic table definition based on the actual inventory row fields returned by OFSC.
192
+
147
193
  ### Activity and inventory helpers
148
194
 
149
195
  ```js
@@ -237,6 +283,8 @@ Top-level exports include:
237
283
  - `downloadWorkZoneCSV`
238
284
  - `downloadAllResourcesCSV`
239
285
  - `downloadAllUsersCSV`
286
+ - `generateAllOnHandInventoryOfAllResourcesCSV`
287
+ - `generateAllOnHandInventoryOfAllResources`
240
288
  - `downloadAllInventoryTypesCSV`
241
289
  - `getInventoryTypesDetail`
242
290
  - `updateCreateInventoryType`