ofsc-utility 1.0.34 → 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 +15 -9
- package/package.json +1 -1
- package/readme.md +2 -0
|
@@ -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,25 +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}`);
|
|
114
|
+
if (!resource)
|
|
115
|
+
continue;
|
|
111
116
|
if (resource.status !== "active") {
|
|
112
117
|
console.log(` ⚠ Skipping inactive resource ${resource.resourceId}`);
|
|
113
118
|
continue;
|
|
114
119
|
}
|
|
115
120
|
offset = 0;
|
|
116
121
|
while (true) {
|
|
117
|
-
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}`;
|
|
118
123
|
try {
|
|
124
|
+
console.log(`➡️ Fetching resources offset=${offset}`);
|
|
119
125
|
const res = await (0, utilities_1.fetchWithRetry)(invUrl, clientId, clientSecret, instanceUrl, token);
|
|
120
126
|
token = res.token;
|
|
121
127
|
const itemsData = res.data;
|
|
@@ -130,9 +136,9 @@ async function generateAllOnHandInventoryOfAllResources(clientId, clientSecret,
|
|
|
130
136
|
rows.push({ resourceName: resource.name, resourceType: resource.resourceType, resourceTimeZone: resource.timeZoneIANA, ...inv, });
|
|
131
137
|
}
|
|
132
138
|
console.log(` ✔ Found ${items.length} Inventories`);
|
|
133
|
-
if (offset +
|
|
139
|
+
if (offset + pageLimit >= itemsData.totalResults)
|
|
134
140
|
break;
|
|
135
|
-
offset +=
|
|
141
|
+
offset += pageLimit;
|
|
136
142
|
}
|
|
137
143
|
catch (err) {
|
|
138
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",
|
package/readme.md
CHANGED
|
@@ -32,6 +32,8 @@ export INSTANCE_NAME=yourInstanceName
|
|
|
32
32
|
export SUBSCRIPTION_ID=yourSubscriptionId
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
- `instanceUrl` is the OFSC instance name only, not the full URL. For example: `mycompany` for `mycompany.fs.ocs.oraclecloud.com`.
|
|
36
|
+
|
|
35
37
|
3. Create a file such as `example.js` and add the sample code below.
|
|
36
38
|
|
|
37
39
|
4. Run the example:
|