ofsc-utility 1.0.35 → 1.0.36
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 +12 -9
- 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,16 +97,19 @@ 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
114
|
if (!resource)
|
|
112
115
|
continue;
|
|
@@ -116,7 +119,7 @@ async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret,
|
|
|
116
119
|
}
|
|
117
120
|
offset = 0;
|
|
118
121
|
while (true) {
|
|
119
|
-
const invUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resource.resourceId)}/inventories/?offset=${offset}&limit=${
|
|
122
|
+
const invUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resource.resourceId)}/inventories/?offset=${offset}&limit=${pageLimit}`;
|
|
120
123
|
try {
|
|
121
124
|
console.log(`➡️ Fetching resources offset=${offset}`);
|
|
122
125
|
const res = await (0, utilities_1.fetchWithRetry)(invUrl, clientId, clientSecret, instanceUrl, token);
|
|
@@ -133,9 +136,9 @@ async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret,
|
|
|
133
136
|
rows.push({ resourceName: resource.name, resourceType: resource.resourceType, resourceTimeZone: resource.timeZoneIANA, ...inv, });
|
|
134
137
|
}
|
|
135
138
|
console.log(` ✔ Found ${items.length} Inventories`);
|
|
136
|
-
if (offset +
|
|
139
|
+
if (offset + pageLimit >= itemsData.totalResults)
|
|
137
140
|
break;
|
|
138
|
-
offset +=
|
|
141
|
+
offset += pageLimit;
|
|
139
142
|
}
|
|
140
143
|
catch (err) {
|
|
141
144
|
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.36",
|
|
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",
|