ofsc-utility 1.0.6 → 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 +6 -1
- package/dist/index.js +10 -2
- package/dist/inventoryTypes/index.d.ts +3 -0
- package/dist/inventoryTypes/index.js +34 -0
- package/dist/types.d.ts +22 -0
- package/package.json +1 -1
- package/readme.md +83 -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';
|
|
@@ -8,12 +9,16 @@ export { getOAuthToken } from './oauthTokenService';
|
|
|
8
9
|
export { downloadWorkZoneCSV } from './workZones';
|
|
9
10
|
export { downloadAllResourcesCSV } from './resources';
|
|
10
11
|
export { downloadAllUsersCSV } from './users';
|
|
11
|
-
export { downloadAllInventoryTypesCSV } from './inventoryTypes';
|
|
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;
|
|
15
17
|
downloadAllResourcesCSV: any;
|
|
16
18
|
downloadAllUsersCSV: any;
|
|
17
19
|
downloadAllInventoryTypesCSV: any;
|
|
20
|
+
getInventoryTypesDetail: any;
|
|
21
|
+
updateInventoryType: any;
|
|
22
|
+
getAllActivities: any;
|
|
18
23
|
};
|
|
19
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.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"));
|
|
@@ -56,6 +57,10 @@ var users_1 = require("./users");
|
|
|
56
57
|
Object.defineProperty(exports, "downloadAllUsersCSV", { enumerable: true, get: function () { return users_1.downloadAllUsersCSV; } });
|
|
57
58
|
var inventoryTypes_1 = require("./inventoryTypes");
|
|
58
59
|
Object.defineProperty(exports, "downloadAllInventoryTypesCSV", { enumerable: true, get: function () { return inventoryTypes_1.downloadAllInventoryTypesCSV; } });
|
|
60
|
+
Object.defineProperty(exports, "getInventoryTypesDetail", { enumerable: true, get: function () { return inventoryTypes_1.getInventoryTypesDetail; } });
|
|
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; } });
|
|
59
64
|
// Default export with all functionality
|
|
60
65
|
const OfscUtility = {
|
|
61
66
|
// Case converters
|
|
@@ -63,6 +68,9 @@ const OfscUtility = {
|
|
|
63
68
|
downloadWorkZoneCSV: require('./workZones').downloadWorkZoneCSV,
|
|
64
69
|
downloadAllResourcesCSV: require('./resources').downloadAllResourcesCSV,
|
|
65
70
|
downloadAllUsersCSV: require('./resources').downloadAllUsersCSV,
|
|
66
|
-
downloadAllInventoryTypesCSV: require('./inventoryTypes').downloadAllInventoryTypesCSV
|
|
71
|
+
downloadAllInventoryTypesCSV: require('./inventoryTypes').downloadAllInventoryTypesCSV,
|
|
72
|
+
getInventoryTypesDetail: require('./inventoryTypes').getInventoryTypesDetail,
|
|
73
|
+
updateInventoryType: require('./inventoryTypes').updateInventoryType,
|
|
74
|
+
getAllActivities: require('./activities').getAllActivities
|
|
67
75
|
};
|
|
68
76
|
exports.default = OfscUtility;
|
|
@@ -1 +1,4 @@
|
|
|
1
|
+
import { InventoryTypePayload, Response } from "../types";
|
|
1
2
|
export declare function downloadAllInventoryTypesCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
|
|
3
|
+
export declare function getInventoryTypesDetail(clientId: string, clientSecret: string, instanceUrl: string, label: string): Promise<Response>;
|
|
4
|
+
export declare function updateCreateInventoryType(clientId: string, clientSecret: string, instanceUrl: string, label: string, payload: InventoryTypePayload): Promise<InventoryTypePayload>;
|
|
@@ -37,6 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.downloadAllInventoryTypesCSV = downloadAllInventoryTypesCSV;
|
|
40
|
+
exports.getInventoryTypesDetail = getInventoryTypesDetail;
|
|
41
|
+
exports.updateCreateInventoryType = updateCreateInventoryType;
|
|
40
42
|
const fs = __importStar(require("fs"));
|
|
41
43
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
42
44
|
const index_1 = require("../oauthTokenService/index");
|
|
@@ -113,3 +115,35 @@ async function downloadAllInventoryTypesCSV(clientId, clientSecret, instanceUrl)
|
|
|
113
115
|
console.log(`🧩 Date Time: ${new Date()}`);
|
|
114
116
|
console.log("-------------------------------------");
|
|
115
117
|
}
|
|
118
|
+
async function getInventoryTypesDetail(clientId, clientSecret, instanceUrl, label) {
|
|
119
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscMetadata/v1/inventoryTypes/${label}`;
|
|
120
|
+
const token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
121
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
122
|
+
method: "GET",
|
|
123
|
+
headers: {
|
|
124
|
+
Authorization: `Bearer ${token}`,
|
|
125
|
+
Accept: "application/json"
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (!res.ok) {
|
|
129
|
+
throw new Error(`❌ Fetch failed: ${res.status} ${res.statusText}`);
|
|
130
|
+
}
|
|
131
|
+
return await res.json();
|
|
132
|
+
}
|
|
133
|
+
async function updateCreateInventoryType(clientId, clientSecret, instanceUrl, label, payload) {
|
|
134
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscMetadata/v1/inventoryTypes/${label}`;
|
|
135
|
+
const token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
136
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
137
|
+
method: "PUT",
|
|
138
|
+
headers: {
|
|
139
|
+
Authorization: `Bearer ${token}`,
|
|
140
|
+
Accept: "application/json",
|
|
141
|
+
"Content-Type": "application/json"
|
|
142
|
+
},
|
|
143
|
+
body: JSON.stringify(payload)
|
|
144
|
+
});
|
|
145
|
+
if (!res.ok) {
|
|
146
|
+
throw new Error(`❌ PUT failed: ${res.status} ${res.statusText}`);
|
|
147
|
+
}
|
|
148
|
+
return await res.json();
|
|
149
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -17,3 +17,25 @@ export interface ResourceResponse {
|
|
|
17
17
|
limit: number;
|
|
18
18
|
totalResults: number;
|
|
19
19
|
}
|
|
20
|
+
export interface Response {
|
|
21
|
+
items: any[];
|
|
22
|
+
offset: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
totalResults: number;
|
|
25
|
+
}
|
|
26
|
+
export interface InventoryTranslation {
|
|
27
|
+
language: string;
|
|
28
|
+
name: string;
|
|
29
|
+
unitOfMeasurement: string;
|
|
30
|
+
languageISO: string;
|
|
31
|
+
}
|
|
32
|
+
export interface InventoryTypePayload {
|
|
33
|
+
label: string;
|
|
34
|
+
name: string;
|
|
35
|
+
unitOfMeasurement: string;
|
|
36
|
+
active: boolean;
|
|
37
|
+
nonSerialized: boolean;
|
|
38
|
+
modelProperty: string;
|
|
39
|
+
quantityPrecision: number;
|
|
40
|
+
translations: InventoryTranslation[];
|
|
41
|
+
}
|
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")
|
|
@@ -32,6 +34,10 @@ npm install ofsc-utility
|
|
|
32
34
|
#### records
|
|
33
35
|
|
|
34
36
|
getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
37
|
+
getInventoryTypesDetail("clientId", "clientSecret", "instanceId"."inventory_label")
|
|
38
|
+
updateCreateInventoryType("clientId", "clientSecret", "instanceId"."inventory_label")
|
|
39
|
+
getAllActivities("clientId", "clientSecret", "instanceId"."resources","dateFrom","dateTo","q","fields")
|
|
40
|
+
|
|
35
41
|
|
|
36
42
|
|
|
37
43
|
## Usage
|
|
@@ -40,6 +46,18 @@ npm install ofsc-utility
|
|
|
40
46
|
|
|
41
47
|
### CommonJS
|
|
42
48
|
|
|
49
|
+
```js
|
|
50
|
+
|
|
51
|
+
async function run (){
|
|
52
|
+
let data = await ofs.InventoryType.getInventoryTypesDetail(
|
|
53
|
+
"clientId", "clientSecret", "instanceId", "inventory_label");
|
|
54
|
+
console.error(data);
|
|
55
|
+
}
|
|
56
|
+
run();
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
|
|
43
61
|
```js
|
|
44
62
|
const ofs = require("ofsc-utility");
|
|
45
63
|
|
|
@@ -91,6 +109,71 @@ ofs
|
|
|
91
109
|
});
|
|
92
110
|
```
|
|
93
111
|
|
|
112
|
+
```js
|
|
113
|
+
const ofs = require('ofsc-utility');
|
|
114
|
+
|
|
115
|
+
async function run() {
|
|
116
|
+
const payload = {
|
|
117
|
+
label: "inventory_label",
|
|
118
|
+
name: "Ordered Part",
|
|
119
|
+
unitOfMeasurement: "ea",
|
|
120
|
+
active: true,
|
|
121
|
+
nonSerialized: true,
|
|
122
|
+
modelProperty: "part_item_number_rev",
|
|
123
|
+
quantityPrecision: 0,
|
|
124
|
+
translations: [
|
|
125
|
+
{
|
|
126
|
+
language: "en",
|
|
127
|
+
name: "Ordered Part",
|
|
128
|
+
unitOfMeasurement: "ea",
|
|
129
|
+
languageISO: "en-US"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const result = await updateCreateInventoryType(
|
|
136
|
+
"CLIENT_ID",
|
|
137
|
+
"CLIENT_SECRET",
|
|
138
|
+
"INSTANCE_URL",
|
|
139
|
+
"inventory_label",
|
|
140
|
+
payload
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
console.log("Updated:", result);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.error(err);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
run();
|
|
150
|
+
|
|
151
|
+
```
|
|
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
|
+
|
|
94
177
|
## License
|
|
95
178
|
|
|
96
179
|
MIT
|