ofsc-utility 1.0.51 → 1.0.53
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 +2 -0
- package/dist/activities/activityActions.d.ts +16 -0
- package/dist/activities/activityActions.js +43 -0
- package/dist/activities/index.d.ts +2 -0
- package/dist/activities/index.js +43 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +19 -6
- package/dist/utilities/index.d.ts +4 -0
- package/dist/utilities/index.js +73 -1
- package/package.json +1 -1
- package/readme.md +218 -36
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
10
10
|
- version 1.0.46
|
|
11
11
|
|
|
12
12
|
### Added
|
|
13
|
+
- Bump version to 1.0.52 and add activity lifecycle actions
|
|
14
|
+
- update version to 1.0.51 and add user/inventory type management functions
|
|
13
15
|
- Bump version to 1.0.50 and add new export functions
|
|
14
16
|
- add user management methods for standalone OFSC
|
|
15
17
|
- Update version and add resource management APIs
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function startActivity(clientId: string, clientSecret: string, instanceUrl: string, activityId: number, token?: string): Promise<{
|
|
2
|
+
token: string;
|
|
3
|
+
data: any;
|
|
4
|
+
}>;
|
|
5
|
+
export declare function cancelActivity(clientId: string, clientSecret: string, instanceUrl: string, activityId: number, token?: string): Promise<{
|
|
6
|
+
token: string;
|
|
7
|
+
data: any;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function completeActivity(clientId: string, clientSecret: string, instanceUrl: string, activityId: number, token?: string): Promise<{
|
|
10
|
+
token: string;
|
|
11
|
+
data: any;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function deleteActivity(clientId: string, clientSecret: string, instanceUrl: string, activityId: number, token?: string): Promise<{
|
|
14
|
+
token: string;
|
|
15
|
+
data: any;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startActivity = startActivity;
|
|
4
|
+
exports.cancelActivity = cancelActivity;
|
|
5
|
+
exports.completeActivity = completeActivity;
|
|
6
|
+
exports.deleteActivity = deleteActivity;
|
|
7
|
+
const utilities_1 = require("../utilities");
|
|
8
|
+
async function startActivity(clientId, clientSecret, instanceUrl, activityId, token = "") {
|
|
9
|
+
if (!activityId || isNaN(activityId)) {
|
|
10
|
+
throw new Error("Invalid activityId. It must be a valid number.");
|
|
11
|
+
}
|
|
12
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/activities/${Number(activityId)}/custom-actions/start`;
|
|
13
|
+
console.log(`➡️ Fetching activity by ID: ${url}`);
|
|
14
|
+
const response = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
15
|
+
return response;
|
|
16
|
+
}
|
|
17
|
+
async function cancelActivity(clientId, clientSecret, instanceUrl, activityId, token = "") {
|
|
18
|
+
if (!activityId || isNaN(activityId)) {
|
|
19
|
+
throw new Error("Invalid activityId. It must be a valid number.");
|
|
20
|
+
}
|
|
21
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/activities/${Number(activityId)}/custom-actions/cancel`;
|
|
22
|
+
console.log(`➡️ Fetching activity by ID: ${url}`);
|
|
23
|
+
const response = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
async function completeActivity(clientId, clientSecret, instanceUrl, activityId, token = "") {
|
|
27
|
+
if (!activityId || isNaN(activityId)) {
|
|
28
|
+
throw new Error("Invalid activityId. It must be a valid number.");
|
|
29
|
+
}
|
|
30
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/activities/${Number(activityId)}/custom-actions/complete`;
|
|
31
|
+
console.log(`Completing activity by ID: ${url}`);
|
|
32
|
+
const response = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
async function deleteActivity(clientId, clientSecret, instanceUrl, activityId, token = "") {
|
|
36
|
+
if (!activityId || isNaN(activityId)) {
|
|
37
|
+
throw new Error("Invalid activityId. It must be a valid number.");
|
|
38
|
+
}
|
|
39
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/activities/${Number(activityId)}`;
|
|
40
|
+
console.log(`Deleting activity by ID: ${url}`);
|
|
41
|
+
const response = await (0, utilities_1.deleteWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { startActivity, cancelActivity, completeActivity, deleteActivity } from "./activityActions";
|
|
1
2
|
/**
|
|
2
3
|
* Fetches all activities from the OFSC instance.
|
|
3
4
|
*
|
|
@@ -17,3 +18,4 @@ export declare function getActivitybyId(clientId: string, clientSecret: string,
|
|
|
17
18
|
token: string;
|
|
18
19
|
data: any;
|
|
19
20
|
}>;
|
|
21
|
+
export declare function getAllNonScheduledActivities(clientId: string, clientSecret: string, instanceUrl: string, rootBucket: string, fields?: string): Promise<any[]>;
|
package/dist/activities/index.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteActivity = exports.completeActivity = exports.cancelActivity = exports.startActivity = void 0;
|
|
3
4
|
exports.getAllActivities = getAllActivities;
|
|
4
5
|
exports.getActivitybyId = getActivitybyId;
|
|
6
|
+
exports.getAllNonScheduledActivities = getAllNonScheduledActivities;
|
|
5
7
|
const oauthTokenService_1 = require("../oauthTokenService");
|
|
6
8
|
const utilities_1 = require("../utilities");
|
|
9
|
+
var activityActions_1 = require("./activityActions");
|
|
10
|
+
Object.defineProperty(exports, "startActivity", { enumerable: true, get: function () { return activityActions_1.startActivity; } });
|
|
11
|
+
Object.defineProperty(exports, "cancelActivity", { enumerable: true, get: function () { return activityActions_1.cancelActivity; } });
|
|
12
|
+
Object.defineProperty(exports, "completeActivity", { enumerable: true, get: function () { return activityActions_1.completeActivity; } });
|
|
13
|
+
Object.defineProperty(exports, "deleteActivity", { enumerable: true, get: function () { return activityActions_1.deleteActivity; } });
|
|
7
14
|
// Validate YYYY-MM-DD format
|
|
8
15
|
const isValidDate = (date) => /^\d{4}-\d{2}-\d{2}$/.test(date);
|
|
9
16
|
/**
|
|
@@ -70,3 +77,39 @@ async function getActivitybyId(clientId, clientSecret, instanceUrl, activityId,
|
|
|
70
77
|
const response = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
71
78
|
return response;
|
|
72
79
|
}
|
|
80
|
+
async function getAllNonScheduledActivities(clientId, clientSecret, instanceUrl, rootBucket, fields) {
|
|
81
|
+
if (!rootBucket) {
|
|
82
|
+
throw new Error("The 'rootBucket' parameter is required to fetch non-scheduled activities.");
|
|
83
|
+
}
|
|
84
|
+
let limit = 1000;
|
|
85
|
+
let offset = 0;
|
|
86
|
+
const allItems = [];
|
|
87
|
+
// Prepare reusable token
|
|
88
|
+
const token = await (0, oauthTokenService_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
89
|
+
while (true) {
|
|
90
|
+
// Build URL cleanly
|
|
91
|
+
const params = new URLSearchParams({
|
|
92
|
+
offset: offset.toString(),
|
|
93
|
+
limit: limit.toString()
|
|
94
|
+
});
|
|
95
|
+
if (rootBucket)
|
|
96
|
+
params.append("resources", rootBucket);
|
|
97
|
+
if (fields)
|
|
98
|
+
params.append("fields", fields);
|
|
99
|
+
params.append("includeNonScheduled", "true");
|
|
100
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/activities/?${params.toString()}`;
|
|
101
|
+
console.error(url);
|
|
102
|
+
console.log(` Fetching Non Scheduled Activities: offset=${offset}, limit=${limit}`);
|
|
103
|
+
const response = await (0, utilities_1.fetchWithRetry)(url, clientId, clientSecret, instanceUrl, token);
|
|
104
|
+
const data = response.data;
|
|
105
|
+
if (!data.items || data.items.length === 0 || data.hasMore === false) {
|
|
106
|
+
console.log("No more items found. Stopping pagination.");
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
allItems.push(...data.items);
|
|
110
|
+
console.log(`Received ${data.items.length} items (Total: ${allItems.length})`);
|
|
111
|
+
limit = data.limit;
|
|
112
|
+
offset += limit;
|
|
113
|
+
}
|
|
114
|
+
return allItems;
|
|
115
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { downloadWorkZoneCSV } from './workZones';
|
|
|
16
16
|
export { AllResources, downloadAllResourcesCSV, getResourcebyId, getworkSkillsOfResource, updateResourcebyId } from './resources';
|
|
17
17
|
export { downloadAllInactiveUsers, downloadAllInactiveUsersCSV, downloadAllUsersCSV, generateUsersCollaborationCSV, getUserByLogin, updateUserbyLogin } from './users';
|
|
18
18
|
export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
|
|
19
|
-
export { getActivitybyId, getAllActivities } from './activities';
|
|
19
|
+
export { getActivitybyId, getAllActivities, startActivity, cancelActivity, completeActivity, deleteActivity, getAllNonScheduledActivities } from './activities';
|
|
20
20
|
export { createActivityCustomerInventories, getActivityCustomerInventories } from './activityInventories';
|
|
21
21
|
export { downloadAllEventsOfDay, downloadAllEventsOfDayCSV, downloadAllEventsOfDLastTwoMinutes, downloadAllEventsOfLastOneHour } from './events';
|
|
22
22
|
export { createExcelFile } from './utilities';
|
|
@@ -29,9 +29,17 @@ declare const OfscUtility: {
|
|
|
29
29
|
downloadAllInventoryTypesCSV: any;
|
|
30
30
|
getInventoryTypesDetail: any;
|
|
31
31
|
updateInventoryType: any;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
Activity: {
|
|
33
|
+
getAllActivities: any;
|
|
34
|
+
getAllNonScheduledActivities: any;
|
|
35
|
+
getActivitybyId: any;
|
|
36
|
+
startActivity: any;
|
|
37
|
+
cancelActivity: any;
|
|
38
|
+
completeActivity: any;
|
|
39
|
+
deleteActivity: any;
|
|
40
|
+
getActivityCustomerInventories: any;
|
|
41
|
+
createActivityCustomerInventories: any;
|
|
42
|
+
};
|
|
35
43
|
metadata: {
|
|
36
44
|
getActivityTypesMetaData: any;
|
|
37
45
|
getActivityTypesGroupsMetaData: any;
|
|
@@ -53,7 +61,7 @@ declare const OfscUtility: {
|
|
|
53
61
|
downloadAllEventsOfLastOneHour: any;
|
|
54
62
|
generateUsersCollaborationCSV: any;
|
|
55
63
|
generateAllOnHandInventoryOfAllResourcesCSV: any;
|
|
56
|
-
|
|
64
|
+
getAllNonScheduledActivities: any;
|
|
57
65
|
AllResources: any;
|
|
58
66
|
getworkSkillsOfResource: any;
|
|
59
67
|
getResource: any;
|
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.updateUserbyLogin = exports.getUserByLogin = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = exports.updateResourcebyId = 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;
|
|
39
|
+
exports.createConfigurationFile = exports.createExcelFile = exports.downloadAllEventsOfLastOneHour = exports.downloadAllEventsOfDLastTwoMinutes = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllNonScheduledActivities = exports.deleteActivity = exports.completeActivity = exports.cancelActivity = exports.startActivity = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.updateUserbyLogin = exports.getUserByLogin = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = exports.updateResourcebyId = 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"));
|
|
@@ -78,6 +78,11 @@ Object.defineProperty(exports, "updateCreateInventoryType", { enumerable: true,
|
|
|
78
78
|
var activities_1 = require("./activities");
|
|
79
79
|
Object.defineProperty(exports, "getActivitybyId", { enumerable: true, get: function () { return activities_1.getActivitybyId; } });
|
|
80
80
|
Object.defineProperty(exports, "getAllActivities", { enumerable: true, get: function () { return activities_1.getAllActivities; } });
|
|
81
|
+
Object.defineProperty(exports, "startActivity", { enumerable: true, get: function () { return activities_1.startActivity; } });
|
|
82
|
+
Object.defineProperty(exports, "cancelActivity", { enumerable: true, get: function () { return activities_1.cancelActivity; } });
|
|
83
|
+
Object.defineProperty(exports, "completeActivity", { enumerable: true, get: function () { return activities_1.completeActivity; } });
|
|
84
|
+
Object.defineProperty(exports, "deleteActivity", { enumerable: true, get: function () { return activities_1.deleteActivity; } });
|
|
85
|
+
Object.defineProperty(exports, "getAllNonScheduledActivities", { enumerable: true, get: function () { return activities_1.getAllNonScheduledActivities; } });
|
|
81
86
|
var activityInventories_1 = require("./activityInventories");
|
|
82
87
|
Object.defineProperty(exports, "createActivityCustomerInventories", { enumerable: true, get: function () { return activityInventories_1.createActivityCustomerInventories; } });
|
|
83
88
|
Object.defineProperty(exports, "getActivityCustomerInventories", { enumerable: true, get: function () { return activityInventories_1.getActivityCustomerInventories; } });
|
|
@@ -99,9 +104,17 @@ const OfscUtility = {
|
|
|
99
104
|
downloadAllInventoryTypesCSV: require('./inventoryTypes').downloadAllInventoryTypesCSV,
|
|
100
105
|
getInventoryTypesDetail: require('./inventoryTypes').getInventoryTypesDetail,
|
|
101
106
|
updateInventoryType: require('./inventoryTypes').updateInventoryType,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
Activity: {
|
|
108
|
+
getAllActivities: require('./activities').getAllActivities,
|
|
109
|
+
getAllNonScheduledActivities: require('./activities').getAllNonScheduledActivities,
|
|
110
|
+
getActivitybyId: require('./activities').getActivitybyId,
|
|
111
|
+
startActivity: require('./activities').startActivity,
|
|
112
|
+
cancelActivity: require('./activities').cancelActivity,
|
|
113
|
+
completeActivity: require('./activities').completeActivity,
|
|
114
|
+
deleteActivity: require('./activities').deleteActivity,
|
|
115
|
+
getActivityCustomerInventories: require('./activityInventories').getActivityCustomerInventories,
|
|
116
|
+
createActivityCustomerInventories: require('./activityInventories').createActivityCustomerInventories,
|
|
117
|
+
},
|
|
105
118
|
metadata: {
|
|
106
119
|
getActivityTypesMetaData: require('./metadata').getActivityTypesMetaData,
|
|
107
120
|
getActivityTypesGroupsMetaData: require('./metadata').getActivityTypesGroupsMetaData,
|
|
@@ -123,8 +136,8 @@ const OfscUtility = {
|
|
|
123
136
|
downloadAllEventsOfLastOneHour: require('./events').downloadAllEventsOfLastOneHour,
|
|
124
137
|
generateUsersCollaborationCSV: require('./users').generateUsersCollaborationCSV,
|
|
125
138
|
generateAllOnHandInventoryOfAllResourcesCSV: require('./inventory').generateAllOnHandInventoryOfAllResourcesCSV,
|
|
126
|
-
|
|
127
|
-
AllResources: require('./
|
|
139
|
+
getAllNonScheduledActivities: require('./activities').getAllNonScheduledActivities,
|
|
140
|
+
AllResources: require('./resources').AllResources,
|
|
128
141
|
getworkSkillsOfResource: require('./resources').getworkSkillsOfResource,
|
|
129
142
|
getResource: require('./resources').getResourcebyId,
|
|
130
143
|
updateResourcebyId: require('./resources').updateResourcebyId,
|
|
@@ -13,6 +13,10 @@ export declare const fetchWithRetry: (url: string, clientId: string, clientSecre
|
|
|
13
13
|
data: any;
|
|
14
14
|
token: string;
|
|
15
15
|
}>;
|
|
16
|
+
export declare const deleteWithRetry: (url: string, clientId: string, clientSecret: string, instanceUrl: string, token: string, retries?: number, baseDelay?: number) => Promise<{
|
|
17
|
+
data: any;
|
|
18
|
+
token: string;
|
|
19
|
+
}>;
|
|
16
20
|
export declare const fetchPatchWithRetry: (url: string, clientId: string, clientSecret: string, instanceUrl: string, token: string, body: any, retries?: number, baseDelay?: number) => Promise<{
|
|
17
21
|
data: any;
|
|
18
22
|
token: string;
|
package/dist/utilities/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.fetchPostWithRetry = exports.fetchPatchWithRetry = exports.fetchWithRetry = void 0;
|
|
39
|
+
exports.fetchPostWithRetry = exports.fetchPatchWithRetry = exports.deleteWithRetry = exports.fetchWithRetry = void 0;
|
|
40
40
|
exports.saveCsv = saveCsv;
|
|
41
41
|
exports.xmlNodeToObjects = xmlNodeToObjects;
|
|
42
42
|
exports.createExcelFile = createExcelFile;
|
|
@@ -122,6 +122,78 @@ const fetchWithRetry = async (url, clientId, clientSecret, instanceUrl, token, r
|
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
124
|
exports.fetchWithRetry = fetchWithRetry;
|
|
125
|
+
const deleteWithRetry = async (url, clientId, clientSecret, instanceUrl, token, retries = 5, baseDelay = 500) => {
|
|
126
|
+
const doDelete = async (bearer) => {
|
|
127
|
+
return fetch(url, {
|
|
128
|
+
method: "DELETE",
|
|
129
|
+
headers: {
|
|
130
|
+
Authorization: `Bearer ${bearer}`,
|
|
131
|
+
Accept: "application/json"
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
console.log(`Deleting ${url}`);
|
|
136
|
+
let currentToken = token;
|
|
137
|
+
let tokenRefreshed = false;
|
|
138
|
+
let remainingRetries = retries;
|
|
139
|
+
let delay = baseDelay;
|
|
140
|
+
while (true) {
|
|
141
|
+
const res = await doDelete(currentToken);
|
|
142
|
+
// Token expired
|
|
143
|
+
if (res.status === 401 && !tokenRefreshed) {
|
|
144
|
+
console.warn("Token expired — renewing token…");
|
|
145
|
+
currentToken = await (0, oauthTokenService_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
146
|
+
tokenRefreshed = true;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const responseText = await res.text();
|
|
150
|
+
const isNoRouteToHost = res.status === 400 &&
|
|
151
|
+
responseText.includes("NoRouteToHostException");
|
|
152
|
+
const isRetryableStatus = res.status === 400 ||
|
|
153
|
+
res.status === 429 ||
|
|
154
|
+
res.status === 502 ||
|
|
155
|
+
res.status === 503 ||
|
|
156
|
+
res.status === 504;
|
|
157
|
+
if ((isRetryableStatus || isNoRouteToHost) &&
|
|
158
|
+
remainingRetries > 0) {
|
|
159
|
+
const retryAfter = res.headers.get("Retry-After");
|
|
160
|
+
let retryDelay = delay;
|
|
161
|
+
if (retryAfter) {
|
|
162
|
+
const retryAfterSeconds = Number(retryAfter);
|
|
163
|
+
if (!Number.isNaN(retryAfterSeconds)) {
|
|
164
|
+
retryDelay = retryAfterSeconds * 1000;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
console.warn(`Retrying DELETE in ${retryDelay}ms... (${remainingRetries} retries left)`);
|
|
168
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
169
|
+
remainingRetries--;
|
|
170
|
+
delay *= 2;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (!res.ok) {
|
|
174
|
+
throw new Error(`DELETE request failed: ${res.status} ${res.statusText}\n${responseText}`);
|
|
175
|
+
}
|
|
176
|
+
// DELETE APIs commonly return 204 No Content
|
|
177
|
+
if (res.status === 204 || !responseText.trim()) {
|
|
178
|
+
return {
|
|
179
|
+
data: null,
|
|
180
|
+
token: currentToken
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
let data;
|
|
184
|
+
try {
|
|
185
|
+
data = JSON.parse(responseText);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw new Error(`Invalid JSON response from ${url}\n${responseText}`);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
data,
|
|
192
|
+
token: currentToken
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
exports.deleteWithRetry = deleteWithRetry;
|
|
125
197
|
const fetchPatchWithRetry = async (url, clientId, clientSecret, instanceUrl, token, body, retries = 5, baseDelay = 500) => {
|
|
126
198
|
const doFetch = async (bearer) => {
|
|
127
199
|
return fetch(url, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
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
|
@@ -102,6 +102,96 @@ async function main() {
|
|
|
102
102
|
main().catch(console.error);
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
## Available exports
|
|
106
|
+
|
|
107
|
+
The package exposes both top-level helpers and grouped namespaces. This list is validated against the actual exports in [src/index.ts](src/index.ts).
|
|
108
|
+
|
|
109
|
+
### Top-level exports
|
|
110
|
+
|
|
111
|
+
- `getOAuthToken`
|
|
112
|
+
- `downloadWorkZoneCSV`
|
|
113
|
+
- `generateAllOnHandInventoryOfAllResources`
|
|
114
|
+
- `generateAllOnHandInventoryOfAllResourcesCSV`
|
|
115
|
+
- `downloadAllResourcesCSV`
|
|
116
|
+
- `AllResources`
|
|
117
|
+
- `getResourcebyId`
|
|
118
|
+
- `getworkSkillsOfResource`
|
|
119
|
+
- `updateResourcebyId`
|
|
120
|
+
- `downloadAllUsersCSV`
|
|
121
|
+
- `downloadAllInactiveUsersCSV`
|
|
122
|
+
- `downloadAllInactiveUsers`
|
|
123
|
+
- `generateUsersCollaborationCSV`
|
|
124
|
+
- `getUserByLogin`
|
|
125
|
+
- `updateUserbyLogin`
|
|
126
|
+
- `downloadAllInventoryTypesCSV`
|
|
127
|
+
- `getInventoryTypesDetail`
|
|
128
|
+
- `updateCreateInventoryType`
|
|
129
|
+
- `getAllActivities`
|
|
130
|
+
- `getAllNonScheduledActivities`
|
|
131
|
+
- `getActivitybyId`
|
|
132
|
+
- `startActivity`
|
|
133
|
+
- `cancelActivity`
|
|
134
|
+
- `completeActivity`
|
|
135
|
+
- `deleteActivity`
|
|
136
|
+
- `getActivityCustomerInventories`
|
|
137
|
+
- `createActivityCustomerInventories`
|
|
138
|
+
- `downloadAllEventsOfDay`
|
|
139
|
+
- `downloadAllEventsOfDayCSV`
|
|
140
|
+
- `downloadAllEventsOfDLastTwoMinutes`
|
|
141
|
+
- `downloadAllEventsOfLastOneHour`
|
|
142
|
+
- `createExcelFile`
|
|
143
|
+
- `createConfigurationFile`
|
|
144
|
+
|
|
145
|
+
### Grouped exports
|
|
146
|
+
|
|
147
|
+
The module-level namespace exports are:
|
|
148
|
+
|
|
149
|
+
- `ofs.Activity`
|
|
150
|
+
- `getAllActivities`
|
|
151
|
+
- `getAllNonScheduledActivities`
|
|
152
|
+
- `getActivitybyId`
|
|
153
|
+
- `startActivity`
|
|
154
|
+
- `cancelActivity`
|
|
155
|
+
- `completeActivity`
|
|
156
|
+
- `deleteActivity`
|
|
157
|
+
- `ofs.ActivityInventories`
|
|
158
|
+
- `getActivityCustomerInventories`
|
|
159
|
+
- `createActivityCustomerInventories`
|
|
160
|
+
- `ofs.Events`
|
|
161
|
+
- `downloadAllEventsOfDay`
|
|
162
|
+
- `downloadAllEventsOfDayCSV`
|
|
163
|
+
- `downloadAllEventsOfDLastTwoMinutes`
|
|
164
|
+
- `downloadAllEventsOfLastOneHour`
|
|
165
|
+
- `ofs.Inventory`
|
|
166
|
+
- `generateAllOnHandInventoryOfAllResources`
|
|
167
|
+
- `generateAllOnHandInventoryOfAllResourcesCSV`
|
|
168
|
+
- `ofs.InventoryType`
|
|
169
|
+
- `downloadAllInventoryTypesCSV`
|
|
170
|
+
- `getInventoryTypesDetail`
|
|
171
|
+
- `updateCreateInventoryType`
|
|
172
|
+
- `ofs.CreateConfigurationFile`
|
|
173
|
+
- `createConfigurationFile`
|
|
174
|
+
- `ofs.OauthTokenService`
|
|
175
|
+
- `getOAuthToken`
|
|
176
|
+
- `ofs.Resource`
|
|
177
|
+
- `AllResources`
|
|
178
|
+
- `downloadAllResourcesCSV`
|
|
179
|
+
- `getResourcebyId`
|
|
180
|
+
- `getworkSkillsOfResource`
|
|
181
|
+
- `updateResourcebyId`
|
|
182
|
+
- `ofs.User`
|
|
183
|
+
- `downloadAllUsersCSV`
|
|
184
|
+
- `downloadAllInactiveUsersCSV`
|
|
185
|
+
- `downloadAllInactiveUsers`
|
|
186
|
+
- `generateUsersCollaborationCSV`
|
|
187
|
+
- `getUserByLogin`
|
|
188
|
+
- `updateUserbyLogin`
|
|
189
|
+
- `ofs.Utilities`
|
|
190
|
+
- `createExcelFile`
|
|
191
|
+
- `ofs.WorkZone`
|
|
192
|
+
- `downloadWorkZoneCSV`
|
|
193
|
+
|
|
194
|
+
|
|
105
195
|
## Complete Example
|
|
106
196
|
|
|
107
197
|
This example shows a full CommonJS script that retrieves activity type metadata and prints the result.
|
|
@@ -759,8 +849,10 @@ This gives you a dynamic table definition based on the actual inventory row fiel
|
|
|
759
849
|
|
|
760
850
|
### Activity and inventory helpers
|
|
761
851
|
|
|
852
|
+
The activity API supports both listing and lifecycle actions. Prefer the grouped namespace for organization:
|
|
853
|
+
|
|
762
854
|
```js
|
|
763
|
-
const activities = await ofs.getAllActivities(
|
|
855
|
+
const activities = await ofs.Activity.getAllActivities(
|
|
764
856
|
process.env.CLIENT_ID,
|
|
765
857
|
process.env.CLIENT_SECRET,
|
|
766
858
|
process.env.INSTANCE_NAME,
|
|
@@ -769,13 +861,71 @@ const activities = await ofs.getAllActivities(
|
|
|
769
861
|
"2025-11-30",
|
|
770
862
|
"status=='pending'",
|
|
771
863
|
"activityId,activityType,date,status",
|
|
864
|
+
true,
|
|
865
|
+
);
|
|
866
|
+
|
|
867
|
+
const activityData = await ofs.Activity.getActivitybyId(
|
|
868
|
+
process.env.CLIENT_ID,
|
|
869
|
+
process.env.CLIENT_SECRET,
|
|
870
|
+
process.env.INSTANCE_NAME,
|
|
871
|
+
123456,
|
|
872
|
+
);
|
|
873
|
+
|
|
874
|
+
const nonScheduledActivities = await ofs.Activity.getAllNonScheduledActivities(
|
|
875
|
+
process.env.CLIENT_ID,
|
|
876
|
+
process.env.CLIENT_SECRET,
|
|
877
|
+
process.env.INSTANCE_NAME,
|
|
878
|
+
"US",
|
|
879
|
+
"activityId,activityType,status",
|
|
880
|
+
);
|
|
881
|
+
|
|
882
|
+
console.log("Non-scheduled activities:", nonScheduledActivities.length);
|
|
883
|
+
|
|
884
|
+
await ofs.Activity.startActivity(
|
|
885
|
+
process.env.CLIENT_ID,
|
|
886
|
+
process.env.CLIENT_SECRET,
|
|
887
|
+
process.env.INSTANCE_NAME,
|
|
888
|
+
123456,
|
|
889
|
+
);
|
|
890
|
+
|
|
891
|
+
await ofs.Activity.completeActivity(
|
|
892
|
+
process.env.CLIENT_ID,
|
|
893
|
+
process.env.CLIENT_SECRET,
|
|
894
|
+
process.env.INSTANCE_NAME,
|
|
895
|
+
123456,
|
|
896
|
+
);
|
|
897
|
+
|
|
898
|
+
await ofs.Activity.cancelActivity(
|
|
899
|
+
process.env.CLIENT_ID,
|
|
900
|
+
process.env.CLIENT_SECRET,
|
|
901
|
+
process.env.INSTANCE_NAME,
|
|
902
|
+
123456,
|
|
903
|
+
);
|
|
904
|
+
|
|
905
|
+
await ofs.Activity.deleteActivity(
|
|
906
|
+
process.env.CLIENT_ID,
|
|
907
|
+
process.env.CLIENT_SECRET,
|
|
908
|
+
process.env.INSTANCE_NAME,
|
|
909
|
+
123456,
|
|
910
|
+
);
|
|
911
|
+
|
|
912
|
+
const customerInventories = await ofs.ActivityInventories.getActivityCustomerInventories(
|
|
913
|
+
process.env.CLIENT_ID,
|
|
914
|
+
process.env.CLIENT_SECRET,
|
|
915
|
+
process.env.INSTANCE_NAME,
|
|
916
|
+
123456,
|
|
772
917
|
);
|
|
773
918
|
|
|
774
|
-
const
|
|
919
|
+
const createdInventory = await ofs.ActivityInventories.createActivityCustomerInventories(
|
|
775
920
|
process.env.CLIENT_ID,
|
|
776
921
|
process.env.CLIENT_SECRET,
|
|
777
922
|
process.env.INSTANCE_NAME,
|
|
778
|
-
|
|
923
|
+
123456,
|
|
924
|
+
{
|
|
925
|
+
code: "INV-1001",
|
|
926
|
+
quantity: 1,
|
|
927
|
+
status: "active",
|
|
928
|
+
},
|
|
779
929
|
);
|
|
780
930
|
|
|
781
931
|
const inventoryDetail = await ofs.InventoryType.getInventoryTypesDetail(
|
|
@@ -786,6 +936,44 @@ const inventoryDetail = await ofs.InventoryType.getInventoryTypesDetail(
|
|
|
786
936
|
);
|
|
787
937
|
```
|
|
788
938
|
|
|
939
|
+
### Activity lifecycle actions
|
|
940
|
+
|
|
941
|
+
The activity action helpers let you transition an OFSC activity through its standard custom actions and list non-scheduled activity work:
|
|
942
|
+
|
|
943
|
+
- `getAllNonScheduledActivities(clientId, clientSecret, instanceUrl, resources, fields?)`
|
|
944
|
+
- `startActivity(clientId, clientSecret, instanceUrl, activityId)`
|
|
945
|
+
- `completeActivity(clientId, clientSecret, instanceUrl, activityId)`
|
|
946
|
+
- `cancelActivity(clientId, clientSecret, instanceUrl, activityId)`
|
|
947
|
+
- `deleteActivity(clientId, clientSecret, instanceUrl, activityId)`
|
|
948
|
+
|
|
949
|
+
Example:
|
|
950
|
+
|
|
951
|
+
```js
|
|
952
|
+
let rootBucket="US";
|
|
953
|
+
const nonScheduled = await ofs.Activity.getAllNonScheduledActivities(
|
|
954
|
+
process.env.CLIENT_ID,
|
|
955
|
+
process.env.CLIENT_SECRET,
|
|
956
|
+
process.env.INSTANCE_NAME,
|
|
957
|
+
rootBucket,
|
|
958
|
+
"activityId,activityType,date,status",
|
|
959
|
+
);
|
|
960
|
+
|
|
961
|
+
console.log(nonScheduled.length);
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
Example:
|
|
965
|
+
|
|
966
|
+
```js
|
|
967
|
+
const started = await ofs.Activity.startActivity(
|
|
968
|
+
process.env.CLIENT_ID,
|
|
969
|
+
process.env.CLIENT_SECRET,
|
|
970
|
+
process.env.INSTANCE_NAME,
|
|
971
|
+
123456,
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
console.log(started.data);
|
|
975
|
+
```
|
|
976
|
+
|
|
789
977
|
### Create a configuration workbook
|
|
790
978
|
|
|
791
979
|
```js
|
|
@@ -842,43 +1030,37 @@ await ofs.User.generateUsersCollaborationCSV(
|
|
|
842
1030
|
);
|
|
843
1031
|
```
|
|
844
1032
|
|
|
845
|
-
## Available exports
|
|
846
1033
|
|
|
847
|
-
|
|
1034
|
+
### Default export object
|
|
848
1035
|
|
|
849
|
-
|
|
850
|
-
- `downloadWorkZoneCSV`
|
|
851
|
-
- `downloadAllResourcesCSV`
|
|
852
|
-
- `getResource`
|
|
853
|
-
- `downloadAllUsersCSV`
|
|
854
|
-
- `downloadAllInactiveUsersCSV`
|
|
855
|
-
- `generateAllOnHandInventoryOfAllResourcesCSV`
|
|
856
|
-
- `generateAllOnHandInventoryOfAllResources`
|
|
857
|
-
- `downloadAllInventoryTypesCSV`
|
|
858
|
-
- `getInventoryTypesDetail`
|
|
859
|
-
- `updateCreateInventoryType`
|
|
860
|
-
- `getAllActivities`
|
|
861
|
-
- `getActivitybyId`
|
|
862
|
-
- `getActivityCustomerInventories`
|
|
863
|
-
- `createActivityCustomerInventories`
|
|
864
|
-
- `downloadAllEventsOfDay`
|
|
865
|
-
- `downloadAllEventsOfDayCSV`
|
|
866
|
-
- `createExcelFile`
|
|
867
|
-
- `createConfigurationFile`
|
|
1036
|
+
The default export object exposes the same functions in a single object, with the metadata helpers grouped under `metadata`:
|
|
868
1037
|
|
|
869
|
-
|
|
1038
|
+
```js
|
|
1039
|
+
const ofs = require("ofsc-utility");
|
|
870
1040
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
-
|
|
877
|
-
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
1041
|
+
const activities = await ofs.Activity.getAllActivities(
|
|
1042
|
+
process.env.CLIENT_ID,
|
|
1043
|
+
process.env.CLIENT_SECRET,
|
|
1044
|
+
process.env.INSTANCE_NAME,
|
|
1045
|
+
"US",
|
|
1046
|
+
"2025-11-01",
|
|
1047
|
+
"2025-11-30",
|
|
1048
|
+
);
|
|
1049
|
+
|
|
1050
|
+
await ofs.Activity.startActivity(
|
|
1051
|
+
process.env.CLIENT_ID,
|
|
1052
|
+
process.env.CLIENT_SECRET,
|
|
1053
|
+
process.env.INSTANCE_NAME,
|
|
1054
|
+
123456,
|
|
1055
|
+
);
|
|
1056
|
+
|
|
1057
|
+
const meta = ofs.metadata;
|
|
1058
|
+
const activityTypes = await meta.getActivityTypesMetaData(
|
|
1059
|
+
process.env.CLIENT_ID,
|
|
1060
|
+
process.env.CLIENT_SECRET,
|
|
1061
|
+
process.env.INSTANCE_NAME,
|
|
1062
|
+
);
|
|
1063
|
+
```
|
|
882
1064
|
|
|
883
1065
|
## Metadata namespace
|
|
884
1066
|
|