ofsc-utility 1.0.35 → 1.0.37
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/inventory/index.d.ts +1 -1
- package/dist/inventory/index.js +15 -10
- package/package.json +1 -1
|
@@ -1,5 +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<{
|
|
2
|
+
export declare function generateAllOnHandInventoryOfAllResources(clientId: string, clientSecret: string, instanceUrl: string, limit?: number): Promise<{
|
|
3
3
|
data: any[];
|
|
4
4
|
props: string[];
|
|
5
5
|
}>;
|
package/dist/inventory/index.js
CHANGED
|
@@ -78,15 +78,15 @@ async function generateAllOnHandInventoryOfAllResourcesCSV(clientId, clientSecre
|
|
|
78
78
|
(0, utilities_1.saveCsv)(rows, filename);
|
|
79
79
|
console.log(`📁 CSV saved: ${fullPath}`);
|
|
80
80
|
}
|
|
81
|
-
async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret, instanceUrl) {
|
|
81
|
+
async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret, instanceUrl, limit) {
|
|
82
82
|
let offset = 0;
|
|
83
|
-
const
|
|
83
|
+
const pageLimit = limit ?? 100;
|
|
84
84
|
const allResources = [];
|
|
85
85
|
let token = "";
|
|
86
86
|
console.log("🚀 Starting all Resources Inventories export...");
|
|
87
87
|
console.log("--------------------------------------------------");
|
|
88
88
|
while (true) {
|
|
89
|
-
const resourcesUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/?offset=${offset}&limit=${
|
|
89
|
+
const resourcesUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/?offset=${offset}&limit=${pageLimit}`;
|
|
90
90
|
console.log(`➡️ Fetching resources offset=${offset}`);
|
|
91
91
|
const res = await (0, utilities_1.fetchWithRetry)(resourcesUrl, clientId, clientSecret, instanceUrl, token);
|
|
92
92
|
token = res.token;
|
|
@@ -97,26 +97,31 @@ async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret,
|
|
|
97
97
|
}
|
|
98
98
|
allResources.push(...data.items);
|
|
99
99
|
console.log(` ✔ Received ${data.items.length} resources (Total: ${allResources.length})`);
|
|
100
|
-
if (offset +
|
|
100
|
+
if (offset + pageLimit >= data.totalResults)
|
|
101
101
|
break;
|
|
102
|
-
offset +=
|
|
102
|
+
offset += pageLimit;
|
|
103
103
|
}
|
|
104
104
|
console.log("--------------------------------------------------");
|
|
105
105
|
console.log(`Total resources to process: ${allResources.length}`);
|
|
106
106
|
console.log("--------------------------------------------------");
|
|
107
107
|
// 2. Fetch on hand inventories for each resource
|
|
108
|
+
const resourcesToProcess = limit
|
|
109
|
+
? allResources.slice(0, limit)
|
|
110
|
+
: allResources;
|
|
108
111
|
const rows = [];
|
|
109
|
-
for (const [index, resource] of
|
|
112
|
+
for (const [index, resource] of resourcesToProcess.entries()) {
|
|
110
113
|
console.log(`${index} 👤 Fetching Inventories for ${resource.resourceId}`);
|
|
111
|
-
if (!resource)
|
|
114
|
+
if (!resource || !resource.resourceId || ["", null, undefined, "undefined"].includes(resource.resourceId)) {
|
|
115
|
+
console.log(`resourceId is misisng for ${JSON.stringify(resource, undefined, 2)}`);
|
|
112
116
|
continue;
|
|
117
|
+
}
|
|
113
118
|
if (resource.status !== "active") {
|
|
114
119
|
console.log(` ⚠ Skipping inactive resource ${resource.resourceId}`);
|
|
115
120
|
continue;
|
|
116
121
|
}
|
|
117
122
|
offset = 0;
|
|
118
123
|
while (true) {
|
|
119
|
-
const invUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resource.resourceId)}/inventories/?offset=${offset}&limit=${
|
|
124
|
+
const invUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resource.resourceId)}/inventories/?offset=${offset}&limit=${pageLimit}`;
|
|
120
125
|
try {
|
|
121
126
|
console.log(`➡️ Fetching resources offset=${offset}`);
|
|
122
127
|
const res = await (0, utilities_1.fetchWithRetry)(invUrl, clientId, clientSecret, instanceUrl, token);
|
|
@@ -133,9 +138,9 @@ async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret,
|
|
|
133
138
|
rows.push({ resourceName: resource.name, resourceType: resource.resourceType, resourceTimeZone: resource.timeZoneIANA, ...inv, });
|
|
134
139
|
}
|
|
135
140
|
console.log(` ✔ Found ${items.length} Inventories`);
|
|
136
|
-
if (offset +
|
|
141
|
+
if (offset + pageLimit >= itemsData.totalResults)
|
|
137
142
|
break;
|
|
138
|
-
offset +=
|
|
143
|
+
offset += pageLimit;
|
|
139
144
|
}
|
|
140
145
|
catch (err) {
|
|
141
146
|
console.error(`❌ Error fetching Inventories for ${resource.resourceId}:`, err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
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",
|