ofsc-utility-browser 1.0.19 → 1.0.21
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.
|
@@ -37,3 +37,4 @@ export declare function getworkSkillsOfResource(clientId: string, clientSecret:
|
|
|
37
37
|
data: any;
|
|
38
38
|
}>;
|
|
39
39
|
export declare function getAllResourcesWorkSkills(clientId: string, clientSecret: string, instanceUrl: string, token?: string, filterByresourceType?: string): Promise<any[]>;
|
|
40
|
+
export declare function AllDescendantsOfResource(clientId: string, clientSecret: string, instanceUrl: string, resourceId: string, initialToken?: string): Promise<any[]>;
|
package/dist/resources/index.js
CHANGED
|
@@ -48,7 +48,7 @@ export async function AllResources(clientId, clientSecret, instanceUrl, filterBy
|
|
|
48
48
|
const res = await fetchWithRetry(url, clientId, clientSecret, instanceUrl, token);
|
|
49
49
|
const { items, totalResults } = res.data;
|
|
50
50
|
const totalFetched = items.length;
|
|
51
|
-
console.log(`Received ${totalFetched} items (Total: ${offset + totalFetched})`);
|
|
51
|
+
console.log(`Resources: Received ${totalFetched} items (Total: ${offset + totalFetched})`);
|
|
52
52
|
if (offset + totalFetched >= totalResults) {
|
|
53
53
|
return items;
|
|
54
54
|
}
|
|
@@ -184,3 +184,54 @@ export async function getAllResourcesWorkSkills(clientId, clientSecret, instance
|
|
|
184
184
|
}
|
|
185
185
|
return csv;
|
|
186
186
|
}
|
|
187
|
+
export async function AllDescendantsOfResource(clientId, clientSecret, instanceUrl, resourceId, initialToken = "") {
|
|
188
|
+
/**
|
|
189
|
+
* The number of API calls made so far.
|
|
190
|
+
* Used to determine if we should wait 10 seconds to avoid server rate limits.
|
|
191
|
+
*/
|
|
192
|
+
let apiCallCount = 0;
|
|
193
|
+
if (!resourceId) {
|
|
194
|
+
throw new Error("Resource ID is required");
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The number of API calls after which we should wait 10 seconds.
|
|
198
|
+
*/
|
|
199
|
+
const WAIT_AFTER_CALLS = 20;
|
|
200
|
+
/**
|
|
201
|
+
* The delay in milliseconds to wait after reaching the API call limit.
|
|
202
|
+
*/
|
|
203
|
+
const DELAY_MS = 10000; // 10 seconds
|
|
204
|
+
/**
|
|
205
|
+
* Sleeps for the given amount of milliseconds.
|
|
206
|
+
*
|
|
207
|
+
* @param {number} ms - The amount of milliseconds to sleep.
|
|
208
|
+
* @returns {Promise<void>} A promise which resolves when the sleep is over.
|
|
209
|
+
*/
|
|
210
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
211
|
+
/**
|
|
212
|
+
* Fetches resources from the OFSC instance.
|
|
213
|
+
*
|
|
214
|
+
* @param {number} offset - The offset from which to fetch resources.
|
|
215
|
+
* @param {string} token - The OAuth token to use.
|
|
216
|
+
* @returns {Promise<ResourceResponse[]>} A promise which resolves to an array of resource responses.
|
|
217
|
+
*/
|
|
218
|
+
const fetchResourcesDescendants = async (offset, token) => {
|
|
219
|
+
apiCallCount++;
|
|
220
|
+
// Wait 10 seconds after 20 API calls to avoid server rate limits.
|
|
221
|
+
if (apiCallCount % WAIT_AFTER_CALLS === 0) {
|
|
222
|
+
console.warn(` Waiting 10 seconds after ${apiCallCount} API calls to avoid server rate limits.`);
|
|
223
|
+
await sleep(DELAY_MS);
|
|
224
|
+
}
|
|
225
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${resourceId}/descendants?offset=${offset}&limit=100`;
|
|
226
|
+
const res = await fetchWithRetry(url, clientId, clientSecret, instanceUrl, token);
|
|
227
|
+
const { items, totalResults } = res.data;
|
|
228
|
+
const totalFetched = items.length;
|
|
229
|
+
console.log(`Resources: Received ${totalFetched} items (Total: ${offset + totalFetched})`);
|
|
230
|
+
if (offset + totalFetched >= totalResults) {
|
|
231
|
+
return items;
|
|
232
|
+
}
|
|
233
|
+
const nextItems = await fetchResourcesDescendants(offset + totalFetched, res.token);
|
|
234
|
+
return [...items, ...nextItems];
|
|
235
|
+
};
|
|
236
|
+
return fetchResourcesDescendants(0, initialToken);
|
|
237
|
+
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -33,6 +33,8 @@ A lightweight utility library for interacting with **Oracle Field Service Cloud
|
|
|
33
33
|
- AllResources(clientId: string,clientSecret: string,instanceUrl: string,filterByresourceType="",initialToken = "")
|
|
34
34
|
- AllUsers(clientId: string,clientSecret: string,instanceUrl: string,initialToken = "")
|
|
35
35
|
- getAllResourcesWorkSkills(clientId: string,clientSecret: string,instanceUrl: string,initialToken = "")
|
|
36
|
+
- resourcePositionHistoryRange( clientID,clientSecret,instanceId,resourceId,fromDate,toDate); // GPS Locations of a technician
|
|
37
|
+
- AllDescendantsOfResource(clientId: string,clientSecret: string,instanceUrl: string,resourceId:string, initialToken = "")
|
|
36
38
|
|
|
37
39
|
### Post Clone
|
|
38
40
|
|
|
@@ -99,6 +101,18 @@ A lightweight utility library for interacting with **Oracle Field Service Cloud
|
|
|
99
101
|
</script>
|
|
100
102
|
```
|
|
101
103
|
|
|
104
|
+
```js
|
|
105
|
+
// Download all GPS Locations
|
|
106
|
+
const res = await window.OFSC.GPS.resourcePositionHistoryRange(clientID,
|
|
107
|
+
clientSecret,
|
|
108
|
+
instanceId,
|
|
109
|
+
resourceId,
|
|
110
|
+
fromDate,
|
|
111
|
+
toDate);
|
|
112
|
+
|
|
113
|
+
window.OFSC.Utilities.downloadCSV(res);
|
|
114
|
+
```
|
|
115
|
+
|
|
102
116
|
```js
|
|
103
117
|
// Download all Resources
|
|
104
118
|
const res = await window.OFSC.Resources.AllResources(clientID, clientSecret, instanceId,"Technician", "");
|