ofsc-utility 1.0.39 → 1.0.41
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 +1 -1
- package/dist/index.js +2 -1
- package/dist/oauthTokenService/index.d.ts +13 -1
- package/dist/oauthTokenService/index.js +52 -19
- package/dist/users/index.d.ts +1 -0
- package/dist/users/index.js +2 -1
- package/package.json +1 -1
- package/readme.md +14 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { generateAllOnHandInventoryOfAllResources, generateAllOnHandInventoryOfA
|
|
|
14
14
|
export { getOAuthToken } from './oauthTokenService';
|
|
15
15
|
export { downloadWorkZoneCSV } from './workZones';
|
|
16
16
|
export { AllResources, downloadAllResourcesCSV, getworkSkillsOfResource } from './resources';
|
|
17
|
-
export { downloadAllInactiveUsersCSV, downloadAllUsersCSV, generateUsersCollaborationCSV } from './users';
|
|
17
|
+
export { downloadAllInactiveUsers, downloadAllInactiveUsersCSV, 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';
|
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.downloadAllEventsOfDLastTwoMinutes = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = 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;
|
|
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.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = 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"));
|
|
@@ -63,6 +63,7 @@ Object.defineProperty(exports, "AllResources", { enumerable: true, get: function
|
|
|
63
63
|
Object.defineProperty(exports, "downloadAllResourcesCSV", { enumerable: true, get: function () { return resources_1.downloadAllResourcesCSV; } });
|
|
64
64
|
Object.defineProperty(exports, "getworkSkillsOfResource", { enumerable: true, get: function () { return resources_1.getworkSkillsOfResource; } });
|
|
65
65
|
var users_1 = require("./users");
|
|
66
|
+
Object.defineProperty(exports, "downloadAllInactiveUsers", { enumerable: true, get: function () { return users_1.downloadAllInactiveUsers; } });
|
|
66
67
|
Object.defineProperty(exports, "downloadAllInactiveUsersCSV", { enumerable: true, get: function () { return users_1.downloadAllInactiveUsersCSV; } });
|
|
67
68
|
Object.defineProperty(exports, "downloadAllUsersCSV", { enumerable: true, get: function () { return users_1.downloadAllUsersCSV; } });
|
|
68
69
|
Object.defineProperty(exports, "generateUsersCollaborationCSV", { enumerable: true, get: function () { return users_1.generateUsersCollaborationCSV; } });
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
interface OAuthTokenOptions {
|
|
2
|
+
/** Max retry attempts for transient (5xx) failures. Default: 2 */
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
/** Base delay in ms between retries (exponential backoff). Default: 1000 */
|
|
5
|
+
retryDelayMs?: number;
|
|
6
|
+
/** Request timeout in ms. Default: 10000 */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Fetches an OAuth access token from OFSC.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getOAuthToken(clientId: string, clientSecret: string, instanceUrl: string, options?: OAuthTokenOptions): Promise<string>;
|
|
13
|
+
export {};
|
|
@@ -1,30 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOAuthToken = getOAuthToken;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Fetches an OAuth access token from OFSC.
|
|
6
|
+
*/
|
|
7
|
+
async function getOAuthToken(clientId, clientSecret, instanceUrl, options = {}) {
|
|
8
|
+
const { maxRetries = 3, retryDelayMs = 1000, timeoutMs = 10000 } = options;
|
|
5
9
|
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/oauthTokenService/v2/token`;
|
|
6
10
|
const credentials = btoa(`${clientId}@${instanceUrl}:${clientSecret}`);
|
|
7
11
|
const headers = {
|
|
8
12
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
9
|
-
'Authorization': `Basic ${credentials}
|
|
13
|
+
'Authorization': `Basic ${credentials}`,
|
|
10
14
|
};
|
|
11
|
-
const body = new URLSearchParams({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const body = new URLSearchParams({ grant_type: 'client_credentials' });
|
|
16
|
+
let lastError;
|
|
17
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
18
|
+
//AbortController is a built-in browser/Node API for cancelling async operations
|
|
19
|
+
// controller.signal & controller.abort() are used to cancel the fetch request if it takes too long
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
22
|
+
try {
|
|
23
|
+
const response = await fetch(url, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers,
|
|
26
|
+
body,
|
|
27
|
+
signal: controller.signal,
|
|
28
|
+
});
|
|
29
|
+
clearTimeout(timeout);
|
|
30
|
+
if (response.ok) {
|
|
31
|
+
const data = (await response.json());
|
|
32
|
+
if (!data.access_token) {
|
|
33
|
+
throw new Error('OAuth response did not contain an access_token');
|
|
34
|
+
}
|
|
35
|
+
return data.access_token;
|
|
36
|
+
}
|
|
37
|
+
// Retry only on server-side / transient errors
|
|
38
|
+
if (response.status >= 500 && response.status < 600 && attempt < maxRetries) {
|
|
39
|
+
lastError = new Error(`OAuth token request failed with status ${response.status}`);
|
|
40
|
+
await delay(retryDelayMs * 2 ** attempt);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
// Non-retriable (4xx) or out of retries — fail fast
|
|
44
|
+
const bodyText = await response.text().catch(() => '');
|
|
45
|
+
throw new Error(`OAuth token request failed: ${response.status} ${response.statusText}${bodyText ? ` - ${bodyText}` : ''}`);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
lastError = error;
|
|
50
|
+
const isAbort = error instanceof Error && error.name === 'AbortError';
|
|
51
|
+
const isNetworkError = error instanceof TypeError;
|
|
52
|
+
if ((isAbort || isNetworkError) && attempt < maxRetries) {
|
|
53
|
+
await delay(retryDelayMs * 2 ** attempt);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Failed to fetch OAuth token after ${attempt + 1} attempt(s): ${error instanceof Error ? error.message : String(error)}`);
|
|
22
57
|
}
|
|
23
|
-
const data = await response.json();
|
|
24
|
-
return data.access_token;
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.error('Error fetching OAuth token:', error);
|
|
28
|
-
throw error;
|
|
29
58
|
}
|
|
59
|
+
throw lastError instanceof Error ? lastError : new Error('Failed to fetch OAuth token');
|
|
60
|
+
}
|
|
61
|
+
function delay(ms) {
|
|
62
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
30
63
|
}
|
package/dist/users/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const OfscUserUtility: {
|
|
|
4
4
|
generateUsersCollaborationCSV: any;
|
|
5
5
|
downloadAllUsersCSV: typeof downloadAllUsersCSV;
|
|
6
6
|
downloadAllInactiveUsersCSV: typeof downloadAllInactiveUsersCSV;
|
|
7
|
+
downloadAllInactiveUsers: typeof downloadAllInactiveUsers;
|
|
7
8
|
};
|
|
8
9
|
export declare function downloadAllInactiveUsersCSV(clientId: string, clientSecret: string, instanceUrl: string, inactivityThresholdDays?: number): Promise<void>;
|
|
9
10
|
export declare function downloadAllInactiveUsers(clientId: string, clientSecret: string, instanceUrl: string, inactivityThresholdDays?: number): Promise<Record<string, any>[]>;
|
package/dist/users/index.js
CHANGED
|
@@ -122,7 +122,8 @@ Object.defineProperty(exports, "generateUsersCollaborationCSV", { enumerable: tr
|
|
|
122
122
|
const OfscUserUtility = {
|
|
123
123
|
generateUsersCollaborationCSV: require('./collaborationGroups').generateUsersCollaborationCSV,
|
|
124
124
|
downloadAllUsersCSV,
|
|
125
|
-
downloadAllInactiveUsersCSV
|
|
125
|
+
downloadAllInactiveUsersCSV,
|
|
126
|
+
downloadAllInactiveUsers
|
|
126
127
|
};
|
|
127
128
|
/**
|
|
128
129
|
* Returns true if the user is "inactive":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
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
|
@@ -248,7 +248,7 @@ node scripts/test-download-inactive-users.js
|
|
|
248
248
|
users whose last login is within the inactivity threshold, and returns the
|
|
249
249
|
matching users as an array of plain objects. It does not create a CSV file.
|
|
250
250
|
|
|
251
|
-
Unlike `downloadAllInactiveUsersCSV`, users with a blank
|
|
251
|
+
Unlike `downloadAllInactiveUsersCSV`, users with a blank or unparsable
|
|
252
252
|
`lastLoginTime` are skipped. The threshold defaults to `14` days, and a user is
|
|
253
253
|
included only when the time since the last login is strictly greater than the
|
|
254
254
|
threshold.
|
|
@@ -301,6 +301,19 @@ downloadAllInactiveUsers(
|
|
|
301
301
|
The helper retrieves users in pages of 100 records and requires valid OFSC API
|
|
302
302
|
credentials.
|
|
303
303
|
|
|
304
|
+
To run the repository test script against a built distribution:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
npm run build
|
|
308
|
+
export CLIENT_ID=yourClientId
|
|
309
|
+
export CLIENT_SECRET=yourClientSecret
|
|
310
|
+
export INSTANCE_URL=yourInstanceName
|
|
311
|
+
export INACTIVITY_THRESHOLD_DAYS=14
|
|
312
|
+
node scripts/test-download-inactive-users-data.js
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
`INACTIVITY_THRESHOLD_DAYS` is optional in the test script and defaults to `14`.
|
|
316
|
+
|
|
304
317
|
### Resource related methods
|
|
305
318
|
|
|
306
319
|
```js
|