ofsc-utility 1.0.43 → 1.0.45
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/resources/index.d.ts +3 -1
- package/dist/resources/index.js +9 -0
- package/dist/utilities/index.js +14 -7
- package/package.json +9 -4
- package/readme.md +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- release v1.0.44 with getResource function and updated keywords
|
|
11
|
+
- version 1.0.43 with built-in resilience and exponential backoff
|
|
12
|
+
- Add -c flag to skip CHANGELOG updates and auto-update logic
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export * from './types';
|
|
|
13
13
|
export { generateAllOnHandInventoryOfAllResources, generateAllOnHandInventoryOfAllResourcesCSV } from './inventory';
|
|
14
14
|
export { getOAuthToken } from './oauthTokenService';
|
|
15
15
|
export { downloadWorkZoneCSV } from './workZones';
|
|
16
|
-
export { AllResources, downloadAllResourcesCSV, getworkSkillsOfResource } from './resources';
|
|
16
|
+
export { AllResources, downloadAllResourcesCSV, getResourcebyId, getworkSkillsOfResource } from './resources';
|
|
17
17
|
export { downloadAllInactiveUsers, downloadAllInactiveUsersCSV, downloadAllUsersCSV, generateUsersCollaborationCSV } from './users';
|
|
18
18
|
export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
|
|
19
19
|
export { getActivitybyId, getAllActivities } from './activities';
|
|
@@ -56,6 +56,7 @@ declare const OfscUtility: {
|
|
|
56
56
|
getActivitybyId: any;
|
|
57
57
|
AllResources: any;
|
|
58
58
|
getworkSkillsOfResource: any;
|
|
59
|
+
getResource: any;
|
|
59
60
|
createExcelFile: any;
|
|
60
61
|
};
|
|
61
62
|
export default OfscUtility;
|
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.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;
|
|
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.getResourcebyId = 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"));
|
|
@@ -61,6 +61,7 @@ Object.defineProperty(exports, "downloadWorkZoneCSV", { enumerable: true, get: f
|
|
|
61
61
|
var resources_1 = require("./resources");
|
|
62
62
|
Object.defineProperty(exports, "AllResources", { enumerable: true, get: function () { return resources_1.AllResources; } });
|
|
63
63
|
Object.defineProperty(exports, "downloadAllResourcesCSV", { enumerable: true, get: function () { return resources_1.downloadAllResourcesCSV; } });
|
|
64
|
+
Object.defineProperty(exports, "getResourcebyId", { enumerable: true, get: function () { return resources_1.getResourcebyId; } });
|
|
64
65
|
Object.defineProperty(exports, "getworkSkillsOfResource", { enumerable: true, get: function () { return resources_1.getworkSkillsOfResource; } });
|
|
65
66
|
var users_1 = require("./users");
|
|
66
67
|
Object.defineProperty(exports, "downloadAllInactiveUsers", { enumerable: true, get: function () { return users_1.downloadAllInactiveUsers; } });
|
|
@@ -122,6 +123,7 @@ const OfscUtility = {
|
|
|
122
123
|
getActivitybyId: require('./activities').getActivitybyId,
|
|
123
124
|
AllResources: require('./activities').AllResources,
|
|
124
125
|
getworkSkillsOfResource: require('./resources').getworkSkillsOfResource,
|
|
126
|
+
getResource: require('./resources').getResourcebyId,
|
|
125
127
|
createExcelFile: require('./utilities').createExcelFile
|
|
126
128
|
};
|
|
127
129
|
exports.default = OfscUtility;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { ResourceResponse } from "../types";
|
|
1
2
|
export declare function downloadAllResourcesCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
|
|
2
|
-
export declare function AllResources(clientId: string, clientSecret: string, instanceUrl: string, initialToken?: string): Promise<
|
|
3
|
+
export declare function AllResources(clientId: string, clientSecret: string, instanceUrl: string, initialToken?: string): Promise<ResourceResponse[]>;
|
|
3
4
|
export declare function getworkSkillsOfResource(clientId: string, clientSecret: string, instanceUrl: string, resourceId: number, token?: string): Promise<{
|
|
4
5
|
token: string;
|
|
5
6
|
data: any;
|
|
6
7
|
}>;
|
|
8
|
+
export declare function getResourcebyId(resourceId: string, clientId: string, clientSecret: string, instanceUrl: string, initialToken?: string): Promise<ResourceResponse>;
|
package/dist/resources/index.js
CHANGED
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.downloadAllResourcesCSV = downloadAllResourcesCSV;
|
|
40
40
|
exports.AllResources = AllResources;
|
|
41
41
|
exports.getworkSkillsOfResource = getworkSkillsOfResource;
|
|
42
|
+
exports.getResourcebyId = getResourcebyId;
|
|
42
43
|
const fs = __importStar(require("fs"));
|
|
43
44
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
45
|
const index_1 = require("../oauthTokenService/index");
|
|
@@ -140,3 +141,11 @@ async function getworkSkillsOfResource(clientId, clientSecret, instanceUrl, reso
|
|
|
140
141
|
data: response.data.items
|
|
141
142
|
};
|
|
142
143
|
}
|
|
144
|
+
async function getResourcebyId(resourceId, clientId, clientSecret, instanceUrl, initialToken = "") {
|
|
145
|
+
const fetchResources = async (offset, token) => {
|
|
146
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/${encodeURIComponent(resourceId)}?offset=${offset}&limit=100`;
|
|
147
|
+
const res = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
148
|
+
return res.data;
|
|
149
|
+
};
|
|
150
|
+
return fetchResources(0, initialToken);
|
|
151
|
+
}
|
package/dist/utilities/index.js
CHANGED
|
@@ -68,28 +68,35 @@ const fetchWithRetry = async (url, clientId, clientSecret, instanceUrl, token, r
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
|
-
console.log(
|
|
71
|
+
console.log(`Fetching ${url}`);
|
|
72
72
|
// Try with the current token
|
|
73
73
|
let res = await doFetch(token);
|
|
74
74
|
/* ---------- 401: refresh token ONCE per call ---------- */
|
|
75
75
|
if (res.status === 401) {
|
|
76
|
-
console.warn("
|
|
76
|
+
console.warn("Token expired — renewing token…");
|
|
77
77
|
token = await (0, oauthTokenService_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
78
78
|
res = await doFetch(token);
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const responseText = await res.text();
|
|
81
|
+
const isNoRouteToHost = res.status === 400 &&
|
|
82
|
+
responseText.includes("NoRouteToHostException");
|
|
83
|
+
const isRetryableStatus = res.status === 429 ||
|
|
84
|
+
res.status === 502 ||
|
|
85
|
+
res.status === 503 ||
|
|
86
|
+
res.status === 504;
|
|
87
|
+
/* ---------- retry with backoff ---------- */
|
|
88
|
+
if ((isRetryableStatus || isNoRouteToHost) && retries > 0) {
|
|
82
89
|
const retryAfter = res.headers.get("Retry-After");
|
|
83
|
-
console.log("
|
|
90
|
+
console.log("Retrying...", retryAfter);
|
|
84
91
|
const delay = retryAfter ? Number(retryAfter) * 1000 : baseDelay;
|
|
85
|
-
console.warn(
|
|
92
|
+
console.warn(`Retrying in ${delay}ms... (${retries} left)`);
|
|
86
93
|
await new Promise(r => setTimeout(r, delay));
|
|
87
94
|
return (0, exports.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token, retries - 1, baseDelay * 2);
|
|
88
95
|
}
|
|
89
96
|
// If still not OK → fail
|
|
90
97
|
if (!res.ok) {
|
|
91
98
|
const body = await res.text();
|
|
92
|
-
throw new Error(
|
|
99
|
+
throw new Error(`Request failed: ${res.status} ${res.statusText}\n${body}`);
|
|
93
100
|
}
|
|
94
101
|
// Return parsed JSON + latest token
|
|
95
102
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.45",
|
|
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",
|
|
@@ -14,16 +14,21 @@
|
|
|
14
14
|
"dev": "ts-node src/index.ts"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
|
-
"ofs",
|
|
18
17
|
"oracle",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
18
|
+
"oracle-field-service",
|
|
19
|
+
"oracle-field-service-cloud",
|
|
20
|
+
"ofsc",
|
|
21
|
+
"ofsc-plugin",
|
|
22
|
+
"field-service",
|
|
23
|
+
"oracle-ofsc",
|
|
24
|
+
"oracle-cloud"
|
|
21
25
|
],
|
|
22
26
|
"author": "MOHD AHSHAN DANISH <https://www.linkedin.com/in/mohdahshandanish/>",
|
|
23
27
|
"license": "MIT",
|
|
24
28
|
"files": [
|
|
25
29
|
"dist",
|
|
26
30
|
"README.md",
|
|
31
|
+
"CHANGELOG.md",
|
|
27
32
|
"LICENSE"
|
|
28
33
|
],
|
|
29
34
|
"repository": {
|
package/readme.md
CHANGED