ofsc-utility 1.0.7 → 1.0.8
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/activities/index.d.ts +15 -0
- package/dist/activities/index.js +72 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -2
- package/package.json +1 -1
- package/readme.md +28 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches all activities from the OFSC instance.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} clientId - The OFSC client ID.
|
|
5
|
+
* @param {string} clientSecret - The OFSC client secret.
|
|
6
|
+
* @param {string} instanceUrl - The OFSC instance URL.
|
|
7
|
+
* @param {string} [q] - The query string to filter activities.
|
|
8
|
+
* @param {string} [resources] - The resources to filter activities by. Required.
|
|
9
|
+
* @param {string} [fields] - The fields to include in the response.
|
|
10
|
+
* @param {string} [dateFrom] - The date from which to filter activities.
|
|
11
|
+
* @param {string} [dateTo] - The date to which to filter activities.
|
|
12
|
+
* @returns {Promise<any[]>} A promise which resolves to an array of activity objects.
|
|
13
|
+
* @throws {Error} If the date format is invalid or if the resources parameter is missing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAllActivities(clientId: string, clientSecret: string, instanceUrl: string, resources: string, dateFrom: string, dateTo: string, q?: string, fields?: string): Promise<any[]>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllActivities = getAllActivities;
|
|
4
|
+
const oauthTokenService_1 = require("../oauthTokenService");
|
|
5
|
+
// Validate YYYY-MM-DD format
|
|
6
|
+
const isValidDate = (date) => /^\d{4}-\d{2}-\d{2}$/.test(date);
|
|
7
|
+
/**
|
|
8
|
+
* Fetches all activities from the OFSC instance.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} clientId - The OFSC client ID.
|
|
11
|
+
* @param {string} clientSecret - The OFSC client secret.
|
|
12
|
+
* @param {string} instanceUrl - The OFSC instance URL.
|
|
13
|
+
* @param {string} [q] - The query string to filter activities.
|
|
14
|
+
* @param {string} [resources] - The resources to filter activities by. Required.
|
|
15
|
+
* @param {string} [fields] - The fields to include in the response.
|
|
16
|
+
* @param {string} [dateFrom] - The date from which to filter activities.
|
|
17
|
+
* @param {string} [dateTo] - The date to which to filter activities.
|
|
18
|
+
* @returns {Promise<any[]>} A promise which resolves to an array of activity objects.
|
|
19
|
+
* @throws {Error} If the date format is invalid or if the resources parameter is missing.
|
|
20
|
+
*/
|
|
21
|
+
async function getAllActivities(clientId, clientSecret, instanceUrl, resources, dateFrom, dateTo, q, fields) {
|
|
22
|
+
// Validate date inputs
|
|
23
|
+
if (!isValidDate(dateFrom) || !isValidDate(dateTo)) {
|
|
24
|
+
throw new Error(`❌ Invalid date format. Expected YYYY-MM-DD.`);
|
|
25
|
+
}
|
|
26
|
+
const limit = 100;
|
|
27
|
+
let offset = 0;
|
|
28
|
+
const allItems = [];
|
|
29
|
+
// Prepare reusable token
|
|
30
|
+
const token = await (0, oauthTokenService_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
31
|
+
while (true) {
|
|
32
|
+
// Build URL cleanly
|
|
33
|
+
const params = new URLSearchParams({
|
|
34
|
+
offset: offset.toString(),
|
|
35
|
+
limit: limit.toString()
|
|
36
|
+
});
|
|
37
|
+
if (q)
|
|
38
|
+
params.append("q", q);
|
|
39
|
+
if (resources)
|
|
40
|
+
params.append("resources", resources);
|
|
41
|
+
if (fields)
|
|
42
|
+
params.append("fields", fields);
|
|
43
|
+
if (dateFrom)
|
|
44
|
+
params.append("dateFrom", dateFrom);
|
|
45
|
+
if (dateTo)
|
|
46
|
+
params.append("dateTo", dateTo);
|
|
47
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/activities/?${params.toString()}`;
|
|
48
|
+
console.error(url);
|
|
49
|
+
console.log(`➡️ Fetching offset=${offset}, limit=${limit}`);
|
|
50
|
+
const res = await fetch(url, {
|
|
51
|
+
method: "GET",
|
|
52
|
+
headers: {
|
|
53
|
+
Authorization: `Bearer ${token}`,
|
|
54
|
+
Accept: "application/json"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
const data = (await res.json());
|
|
59
|
+
throw new Error(`❌ Fetch failed: ${res.status} ${res.statusText}\n` +
|
|
60
|
+
`Response: ${JSON.stringify(data, null, 2)}`);
|
|
61
|
+
}
|
|
62
|
+
const data = (await res.json());
|
|
63
|
+
if (!data.items || data.items.length === 0) {
|
|
64
|
+
console.log("✔ No more items found. Stopping pagination.");
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
allItems.push(...data.items);
|
|
68
|
+
console.log(` ✔ Received ${data.items.length} items (Total: ${allItems.length})`);
|
|
69
|
+
offset += limit;
|
|
70
|
+
}
|
|
71
|
+
return allItems;
|
|
72
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * as Activity from './activities';
|
|
1
2
|
export * as InventoryType from './inventoryTypes';
|
|
2
3
|
export * as OauthTokenService from './oauthTokenService';
|
|
3
4
|
export * as Resource from './resources';
|
|
@@ -9,6 +10,7 @@ export { downloadWorkZoneCSV } from './workZones';
|
|
|
9
10
|
export { downloadAllResourcesCSV } from './resources';
|
|
10
11
|
export { downloadAllUsersCSV } from './users';
|
|
11
12
|
export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
|
|
13
|
+
export { getAllActivities } from './activities';
|
|
12
14
|
declare const OfscUtility: {
|
|
13
15
|
getOAuthToken: any;
|
|
14
16
|
downloadWorkZoneCSV: any;
|
|
@@ -17,5 +19,6 @@ declare const OfscUtility: {
|
|
|
17
19
|
downloadAllInventoryTypesCSV: any;
|
|
18
20
|
getInventoryTypesDetail: any;
|
|
19
21
|
updateInventoryType: any;
|
|
22
|
+
getAllActivities: any;
|
|
20
23
|
};
|
|
21
24
|
export default OfscUtility;
|
package/dist/index.js
CHANGED
|
@@ -36,8 +36,9 @@ 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.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.downloadAllUsersCSV = exports.downloadAllResourcesCSV = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.User = exports.Resource = exports.OauthTokenService = exports.InventoryType = void 0;
|
|
39
|
+
exports.getAllActivities = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.downloadAllUsersCSV = exports.downloadAllResourcesCSV = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.User = exports.Resource = exports.OauthTokenService = exports.InventoryType = exports.Activity = void 0;
|
|
40
40
|
// Export all methods grouped by category
|
|
41
|
+
exports.Activity = __importStar(require("./activities"));
|
|
41
42
|
exports.InventoryType = __importStar(require("./inventoryTypes"));
|
|
42
43
|
exports.OauthTokenService = __importStar(require("./oauthTokenService"));
|
|
43
44
|
exports.Resource = __importStar(require("./resources"));
|
|
@@ -58,6 +59,8 @@ var inventoryTypes_1 = require("./inventoryTypes");
|
|
|
58
59
|
Object.defineProperty(exports, "downloadAllInventoryTypesCSV", { enumerable: true, get: function () { return inventoryTypes_1.downloadAllInventoryTypesCSV; } });
|
|
59
60
|
Object.defineProperty(exports, "getInventoryTypesDetail", { enumerable: true, get: function () { return inventoryTypes_1.getInventoryTypesDetail; } });
|
|
60
61
|
Object.defineProperty(exports, "updateCreateInventoryType", { enumerable: true, get: function () { return inventoryTypes_1.updateCreateInventoryType; } });
|
|
62
|
+
var activities_1 = require("./activities");
|
|
63
|
+
Object.defineProperty(exports, "getAllActivities", { enumerable: true, get: function () { return activities_1.getAllActivities; } });
|
|
61
64
|
// Default export with all functionality
|
|
62
65
|
const OfscUtility = {
|
|
63
66
|
// Case converters
|
|
@@ -67,6 +70,7 @@ const OfscUtility = {
|
|
|
67
70
|
downloadAllUsersCSV: require('./resources').downloadAllUsersCSV,
|
|
68
71
|
downloadAllInventoryTypesCSV: require('./inventoryTypes').downloadAllInventoryTypesCSV,
|
|
69
72
|
getInventoryTypesDetail: require('./inventoryTypes').getInventoryTypesDetail,
|
|
70
|
-
updateInventoryType: require('./inventoryTypes').updateInventoryType
|
|
73
|
+
updateInventoryType: require('./inventoryTypes').updateInventoryType,
|
|
74
|
+
getAllActivities: require('./activities').getAllActivities
|
|
71
75
|
};
|
|
72
76
|
exports.default = OfscUtility;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -21,6 +21,8 @@ npm install ofsc-utility
|
|
|
21
21
|
|
|
22
22
|
### Download
|
|
23
23
|
|
|
24
|
+
Please see the code snippet below.
|
|
25
|
+
|
|
24
26
|
#### csv
|
|
25
27
|
|
|
26
28
|
downloadWorkZoneCSV("clientId", "clientSecret", "instanceId")
|
|
@@ -33,6 +35,8 @@ npm install ofsc-utility
|
|
|
33
35
|
|
|
34
36
|
getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
35
37
|
getInventoryTypesDetail("clientId", "clientSecret", "instanceId"."inventory_label")
|
|
38
|
+
updateCreateInventoryType("clientId", "clientSecret", "instanceId"."inventory_label")
|
|
39
|
+
getAllActivities("clientId", "clientSecret", "instanceId"."resources","dateFrom","dateTo","q","fields")
|
|
36
40
|
|
|
37
41
|
|
|
38
42
|
|
|
@@ -146,6 +150,30 @@ run();
|
|
|
146
150
|
|
|
147
151
|
```
|
|
148
152
|
|
|
153
|
+
```js
|
|
154
|
+
const ofs = require("ofsc-utility");
|
|
155
|
+
async function run() {
|
|
156
|
+
try {
|
|
157
|
+
const result = await ofs.getAllActivities(
|
|
158
|
+
(clientId = "CLIENT_ID"),
|
|
159
|
+
(clientSecret = "CLIENT_SECRET"),
|
|
160
|
+
(instanceUrl = "INSTANCE_URL"),
|
|
161
|
+
(resources = "US"),
|
|
162
|
+
(dateFrom = "2025-11-05"),
|
|
163
|
+
(dateTo = "2025-12-05"),
|
|
164
|
+
(q = "status=='pending' and ACTIVITY_NOTES!=''"),
|
|
165
|
+
(fields = "ACTIVITY_NOTES,status,activityId,activityType,date,resourceId")
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
console.log("Updated:", result);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
console.error(err);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
run();
|
|
175
|
+
```
|
|
176
|
+
|
|
149
177
|
## License
|
|
150
178
|
|
|
151
179
|
MIT
|