ofsc-utility 1.0.2 → 1.0.4
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 +6 -0
- package/dist/index.js +9 -1
- package/dist/resources/index.d.ts +1 -0
- package/dist/resources/index.js +115 -0
- package/dist/types.d.ts +18 -3
- package/dist/workZones/index.d.ts +1 -0
- package/dist/workZones/index.js +96 -0
- package/package.json +10 -6
- package/readme.md +29 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export * as OauthTokenService from './oauthTokenService';
|
|
2
|
+
export * as Resource from './resources';
|
|
3
|
+
export * as WorkZone from './workZones';
|
|
2
4
|
export * from './types';
|
|
3
5
|
export { getOAuthToken } from './oauthTokenService';
|
|
6
|
+
export { downloadWorkZoneCSV } from './workZones';
|
|
7
|
+
export { downloadAllResourcesCSV } from './resources';
|
|
4
8
|
declare const OfscUtility: {
|
|
5
9
|
getOAuthToken: any;
|
|
10
|
+
downloadWorkZoneCSV: any;
|
|
11
|
+
downloadAllResourcesCSV: any;
|
|
6
12
|
};
|
|
7
13
|
export default OfscUtility;
|
package/dist/index.js
CHANGED
|
@@ -36,17 +36,25 @@ 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.getOAuthToken = exports.OauthTokenService = void 0;
|
|
39
|
+
exports.downloadAllResourcesCSV = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.Resource = exports.OauthTokenService = void 0;
|
|
40
40
|
// Export all methods grouped by category
|
|
41
41
|
exports.OauthTokenService = __importStar(require("./oauthTokenService"));
|
|
42
|
+
exports.Resource = __importStar(require("./resources"));
|
|
43
|
+
exports.WorkZone = __importStar(require("./workZones"));
|
|
42
44
|
// Export types
|
|
43
45
|
__exportStar(require("./types"), exports);
|
|
44
46
|
// Export individual popular methods for convenience
|
|
45
47
|
var oauthTokenService_1 = require("./oauthTokenService");
|
|
46
48
|
Object.defineProperty(exports, "getOAuthToken", { enumerable: true, get: function () { return oauthTokenService_1.getOAuthToken; } });
|
|
49
|
+
var workZones_1 = require("./workZones");
|
|
50
|
+
Object.defineProperty(exports, "downloadWorkZoneCSV", { enumerable: true, get: function () { return workZones_1.downloadWorkZoneCSV; } });
|
|
51
|
+
var resources_1 = require("./resources");
|
|
52
|
+
Object.defineProperty(exports, "downloadAllResourcesCSV", { enumerable: true, get: function () { return resources_1.downloadAllResourcesCSV; } });
|
|
47
53
|
// Default export with all functionality
|
|
48
54
|
const OfscUtility = {
|
|
49
55
|
// Case converters
|
|
50
56
|
getOAuthToken: require('./oauthTokenService').getOAuthToken,
|
|
57
|
+
downloadWorkZoneCSV: require('./workZones').downloadWorkZoneCSV,
|
|
58
|
+
downloadAllResourcesCSV: require('./resources').downloadAllResourcesCSV
|
|
51
59
|
};
|
|
52
60
|
exports.default = OfscUtility;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadAllResourcesCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.downloadAllResourcesCSV = downloadAllResourcesCSV;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
42
|
+
const index_1 = require("../oauthTokenService/index");
|
|
43
|
+
async function downloadAllResourcesCSV(clientId, clientSecret, instanceUrl) {
|
|
44
|
+
let offset = 0;
|
|
45
|
+
const limit = 100;
|
|
46
|
+
let allItems = [];
|
|
47
|
+
let totalFetched = 0;
|
|
48
|
+
console.log("🚀 Starting resource download...");
|
|
49
|
+
console.log("-------------------------------------");
|
|
50
|
+
while (true) {
|
|
51
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/resources/?offset=${offset}&limit=${limit}`;
|
|
52
|
+
const token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
53
|
+
console.log(`➡️ Fetching offset=${offset} limit=${limit}`);
|
|
54
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
55
|
+
method: "GET",
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: `Bearer ${token}`,
|
|
58
|
+
Accept: "application/json"
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
throw new Error(`❌ Fetch failed: ${res.status} ${res.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
const data = (await res.json());
|
|
65
|
+
allItems.push(...data.items);
|
|
66
|
+
totalFetched += data.items.length;
|
|
67
|
+
console.log(` ✔ Received ${data.items.length} items (Total: ${totalFetched})`);
|
|
68
|
+
if (offset + limit >= data.totalResults)
|
|
69
|
+
break;
|
|
70
|
+
offset += limit;
|
|
71
|
+
}
|
|
72
|
+
console.log("-------------------------------------");
|
|
73
|
+
console.log("🧩 Collecting all unique properties...");
|
|
74
|
+
// Collect union of all properties
|
|
75
|
+
const allProperties = new Set();
|
|
76
|
+
for (const item of allItems) {
|
|
77
|
+
for (const key of Object.keys(item)) {
|
|
78
|
+
if (!["links", "inventories", "users", "workZones", "workSkills", "workSchedules"].includes(key)) {
|
|
79
|
+
allProperties.add(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const headers = Array.from(allProperties);
|
|
84
|
+
console.log(`📝 Total unique fields: ${headers.length}`);
|
|
85
|
+
// Build CSV rows
|
|
86
|
+
const csvRows = [];
|
|
87
|
+
csvRows.push(headers.join(","));
|
|
88
|
+
for (const item of allItems) {
|
|
89
|
+
const row = headers.map(field => {
|
|
90
|
+
let value = item[field];
|
|
91
|
+
if (field === "keys") {
|
|
92
|
+
if (Array.isArray(value))
|
|
93
|
+
return `"${value.join("|")}"`;
|
|
94
|
+
if (value)
|
|
95
|
+
return `"${String(value)}"`;
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
// Objects → JSON-safe string
|
|
99
|
+
if (typeof value === "object" && value !== null) {
|
|
100
|
+
return `"${JSON.stringify(value).replace(/"/g, "'")}"`;
|
|
101
|
+
}
|
|
102
|
+
return value !== undefined ? `"${String(value).replace(/"/g, "'")}"` : "";
|
|
103
|
+
});
|
|
104
|
+
csvRows.push(row.join(","));
|
|
105
|
+
}
|
|
106
|
+
const filePath = "./resources.csv";
|
|
107
|
+
fs.writeFileSync(filePath, csvRows.join("\n"));
|
|
108
|
+
console.log("-------------------------------------");
|
|
109
|
+
console.log("✅ Resource CSV Created Successfully!");
|
|
110
|
+
console.log(`📁 File: ${filePath}`);
|
|
111
|
+
console.log(`📦 Total Records: ${totalFetched}`);
|
|
112
|
+
console.log(`🧩 Total Columns (Dynamic): ${headers.length}`);
|
|
113
|
+
console.log(`🧩 Date Time: ${new Date()}`);
|
|
114
|
+
console.log("-------------------------------------");
|
|
115
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface WorkZoneItem {
|
|
2
|
+
workZoneLabel: string;
|
|
3
|
+
workZoneName: string;
|
|
4
|
+
status: string;
|
|
5
|
+
travelArea: string;
|
|
6
|
+
keys: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface WorkZoneResponse {
|
|
9
|
+
items: WorkZoneItem[];
|
|
10
|
+
hasMore: boolean;
|
|
11
|
+
offset: number;
|
|
12
|
+
totalResults: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ResourceResponse {
|
|
15
|
+
items: any[];
|
|
16
|
+
offset: number;
|
|
17
|
+
limit: number;
|
|
18
|
+
totalResults: number;
|
|
4
19
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadWorkZoneCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.downloadWorkZoneCSV = downloadWorkZoneCSV;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
42
|
+
const index_1 = require("../oauthTokenService/index");
|
|
43
|
+
async function downloadWorkZoneCSV(clientId, clientSecret, instanceUrl) {
|
|
44
|
+
const startTime = Date.now();
|
|
45
|
+
let offset = 0;
|
|
46
|
+
const limit = 100;
|
|
47
|
+
let totalWorkZones = 0;
|
|
48
|
+
let totalKeys = 0;
|
|
49
|
+
let csvRows = [
|
|
50
|
+
"workZoneLabel,workZoneName,key,status,travelArea"
|
|
51
|
+
];
|
|
52
|
+
while (true) {
|
|
53
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscMetadata/v1/workZones?offset=${offset}&limit=${limit}`;
|
|
54
|
+
let token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
55
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
56
|
+
method: "GET",
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: `Bearer ${token}`,
|
|
59
|
+
Accept: "application/json"
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
throw new Error(`Failed to fetch work zones: ${res.status} ${res.statusText}`);
|
|
64
|
+
}
|
|
65
|
+
const data = (await res.json());
|
|
66
|
+
totalWorkZones += data.items.length;
|
|
67
|
+
for (const item of data.items) {
|
|
68
|
+
// Normalize keys (ensure it's always an array)
|
|
69
|
+
const keys = Array.isArray(item.keys)
|
|
70
|
+
? item.keys
|
|
71
|
+
: item.keys
|
|
72
|
+
? [item.keys]
|
|
73
|
+
: [];
|
|
74
|
+
totalKeys += keys.length;
|
|
75
|
+
for (const key of keys) {
|
|
76
|
+
csvRows.push(`${item.workZoneLabel},${item.workZoneName},${key},${item.status},${item.travelArea}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!data.hasMore)
|
|
80
|
+
break;
|
|
81
|
+
offset = data.offset + limit;
|
|
82
|
+
}
|
|
83
|
+
const csv = csvRows.join("\n");
|
|
84
|
+
const filePath = "./workzones.csv";
|
|
85
|
+
fs.writeFileSync(filePath, csv);
|
|
86
|
+
const endTime = Date.now();
|
|
87
|
+
const durationSec = ((endTime - startTime) / 1000).toFixed(2);
|
|
88
|
+
// --- Summary ---
|
|
89
|
+
console.log("\n=== Work Zone Extraction Summary ===");
|
|
90
|
+
console.log(`Total Work Zones Processed : ${totalWorkZones}`);
|
|
91
|
+
console.log(`Total Keys Extracted : ${totalKeys}`);
|
|
92
|
+
console.log(`CSV Saved To : ${filePath}`);
|
|
93
|
+
console.log(`Time Taken : ${durationSec} sec`);
|
|
94
|
+
console.log("====================================\n");
|
|
95
|
+
console.log("✔ Work Zone CSV download completed.");
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A wrapper for Oracle Field Service REST API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,11 +29,15 @@
|
|
|
29
29
|
"url": "https://github.com/mailtodanish/ofsc-utility"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"
|
|
32
|
+
"@types/jest": "^29.0.0",
|
|
33
33
|
"@types/node": "^20.0.0",
|
|
34
|
-
"
|
|
34
|
+
"@types/node-fetch": "^2.6.13",
|
|
35
35
|
"jest": "^29.0.0",
|
|
36
|
-
"
|
|
37
|
-
"ts-
|
|
36
|
+
"ts-jest": "^29.0.0",
|
|
37
|
+
"ts-node": "^10.9.0",
|
|
38
|
+
"typescript": "^5.0.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"node-fetch": "^2.7.0"
|
|
38
42
|
}
|
|
39
|
-
}
|
|
43
|
+
}
|
package/readme.md
CHANGED
|
@@ -17,6 +17,14 @@ A lightweight utility library for interacting with **Oracle Field Service Cloud
|
|
|
17
17
|
npm install ofsc-utility
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
## Functions implemented
|
|
21
|
+
|
|
22
|
+
### Download
|
|
23
|
+
downloadWorkZoneCSV(clientId, clientSecret, instanceId)
|
|
24
|
+
downloadAllResourcesCSV(clientId, clientSecret, instanceId)
|
|
25
|
+
getOAuthToken(clientId, clientSecret, instanceId)
|
|
26
|
+
|
|
27
|
+
|
|
20
28
|
## Usage
|
|
21
29
|
|
|
22
30
|
### CommonJS
|
|
@@ -33,10 +41,25 @@ ofs.getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
|
33
41
|
});
|
|
34
42
|
```
|
|
35
43
|
|
|
36
|
-
## Parameters
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
``` js
|
|
46
|
+
const ofs = require('ofsc-utility');
|
|
47
|
+
|
|
48
|
+
ofs.WorkZone.downloadWorkZoneCSV("clientId", "clientSecret", "instanceId").then((token) => {
|
|
49
|
+
console.log(token);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
``` js
|
|
54
|
+
const ofs = require('ofsc-utility');
|
|
55
|
+
|
|
56
|
+
ofs.downloadAllResourcesCSV("clientId", "clientSecret", "instanceId").then((token) => {
|
|
57
|
+
console.log(token);
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT
|
|
64
|
+
|
|
65
|
+
|