ofsc-utility 1.0.3 โ 1.0.5
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 +6 -0
- package/dist/users/index.d.ts +1 -0
- package/dist/users/index.js +115 -0
- package/package.json +1 -1
- package/readme.md +49 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
export * as OauthTokenService from './oauthTokenService';
|
|
2
|
+
export * as Resource from './resources';
|
|
3
|
+
export * as User from './users';
|
|
2
4
|
export * as WorkZone from './workZones';
|
|
3
5
|
export * from './types';
|
|
4
6
|
export { getOAuthToken } from './oauthTokenService';
|
|
5
7
|
export { downloadWorkZoneCSV } from './workZones';
|
|
8
|
+
export { downloadAllResourcesCSV } from './resources';
|
|
9
|
+
export { downloadAllUsersCSV } from './users';
|
|
6
10
|
declare const OfscUtility: {
|
|
7
11
|
getOAuthToken: any;
|
|
8
12
|
downloadWorkZoneCSV: any;
|
|
13
|
+
downloadAllResourcesCSV: any;
|
|
14
|
+
downloadAllUsersCSV: any;
|
|
9
15
|
};
|
|
10
16
|
export default OfscUtility;
|
package/dist/index.js
CHANGED
|
@@ -36,9 +36,11 @@ 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.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.OauthTokenService = void 0;
|
|
39
|
+
exports.downloadAllUsersCSV = exports.downloadAllResourcesCSV = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.User = 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.User = __importStar(require("./users"));
|
|
42
44
|
exports.WorkZone = __importStar(require("./workZones"));
|
|
43
45
|
// Export types
|
|
44
46
|
__exportStar(require("./types"), exports);
|
|
@@ -47,10 +49,16 @@ var oauthTokenService_1 = require("./oauthTokenService");
|
|
|
47
49
|
Object.defineProperty(exports, "getOAuthToken", { enumerable: true, get: function () { return oauthTokenService_1.getOAuthToken; } });
|
|
48
50
|
var workZones_1 = require("./workZones");
|
|
49
51
|
Object.defineProperty(exports, "downloadWorkZoneCSV", { enumerable: true, get: function () { return workZones_1.downloadWorkZoneCSV; } });
|
|
52
|
+
var resources_1 = require("./resources");
|
|
53
|
+
Object.defineProperty(exports, "downloadAllResourcesCSV", { enumerable: true, get: function () { return resources_1.downloadAllResourcesCSV; } });
|
|
54
|
+
var users_1 = require("./users");
|
|
55
|
+
Object.defineProperty(exports, "downloadAllUsersCSV", { enumerable: true, get: function () { return users_1.downloadAllUsersCSV; } });
|
|
50
56
|
// Default export with all functionality
|
|
51
57
|
const OfscUtility = {
|
|
52
58
|
// Case converters
|
|
53
59
|
getOAuthToken: require('./oauthTokenService').getOAuthToken,
|
|
54
60
|
downloadWorkZoneCSV: require('./workZones').downloadWorkZoneCSV,
|
|
61
|
+
downloadAllResourcesCSV: require('./resources').downloadAllResourcesCSV,
|
|
62
|
+
downloadAllUsersCSV: require('./resources').downloadAllUsersCSV
|
|
55
63
|
};
|
|
56
64
|
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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadAllUsersCSV(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.downloadAllUsersCSV = downloadAllUsersCSV;
|
|
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 downloadAllUsersCSV(clientId, clientSecret, instanceUrl) {
|
|
44
|
+
let offset = 0;
|
|
45
|
+
const limit = 100;
|
|
46
|
+
let allItems = [];
|
|
47
|
+
let totalFetched = 0;
|
|
48
|
+
console.log("๐ Starting users download...");
|
|
49
|
+
console.log("-------------------------------------");
|
|
50
|
+
while (true) {
|
|
51
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/users/?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 (!["resources", "collaborationGroups", "resourceInternalIds", "links"].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 = "./users.csv";
|
|
107
|
+
fs.writeFileSync(filePath, csvRows.join("\n"));
|
|
108
|
+
console.log("-------------------------------------");
|
|
109
|
+
console.log("โ
Users 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/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,7 +4,7 @@ A lightweight utility library for interacting with **Oracle Field Service Cloud
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- ๐ **40+ utility methods**
|
|
7
|
+
- ๐ **40+ utility methods**
|
|
8
8
|
- ๐ **Written in TypeScript** with full type definitions
|
|
9
9
|
- ๐งช **Completely tested** with Jest
|
|
10
10
|
- ๐ฆ **Zero dependencies**
|
|
@@ -13,43 +13,76 @@ A lightweight utility library for interacting with **Oracle Field Service Cloud
|
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
|
-
```
|
|
16
|
+
```bash
|
|
17
17
|
npm install ofsc-utility
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Functions implemented
|
|
21
21
|
|
|
22
22
|
### Download
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
downloadWorkZoneCSV("clientId", "clientSecret", "instanceId")
|
|
25
|
+
downloadAllResourcesCSV("clientId", "clientSecret", "instanceId")
|
|
26
|
+
downloadAllUsersCSV("clientId", "clientSecret", "instanceId")
|
|
27
|
+
getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
25
28
|
|
|
26
29
|
## Usage
|
|
27
30
|
|
|
31
|
+
downloadWorkZoneCSV("bot", "XXXXXXXXX", "compXXX.test")
|
|
32
|
+
|
|
28
33
|
### CommonJS
|
|
29
34
|
|
|
30
|
-
```
|
|
31
|
-
const ofs = require(
|
|
35
|
+
```js
|
|
36
|
+
const ofs = require("ofsc-utility");
|
|
32
37
|
|
|
33
|
-
ofs
|
|
38
|
+
ofs
|
|
39
|
+
.getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
34
40
|
.then((token) => {
|
|
35
|
-
|
|
41
|
+
console.log(token);
|
|
36
42
|
})
|
|
37
43
|
.catch((err) => {
|
|
38
|
-
|
|
44
|
+
console.error("Error fetching token:", err);
|
|
39
45
|
});
|
|
40
46
|
```
|
|
41
47
|
|
|
48
|
+
```js
|
|
49
|
+
const ofs = require("ofsc-utility");
|
|
50
|
+
|
|
51
|
+
ofs.WorkZone.downloadWorkZoneCSV("clientId", "clientSecret", "instanceId")
|
|
52
|
+
.then(() => {
|
|
53
|
+
console.log("successful");
|
|
54
|
+
})
|
|
55
|
+
.catch((err) => {
|
|
56
|
+
console.error("Error:", err);
|
|
57
|
+
});
|
|
58
|
+
```
|
|
42
59
|
|
|
43
|
-
```
|
|
44
|
-
const ofs = require(
|
|
60
|
+
```js
|
|
61
|
+
const ofs = require("ofsc-utility");
|
|
45
62
|
|
|
46
|
-
ofs
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
ofs
|
|
64
|
+
.downloadAllResourcesCSV("clientId", "clientSecret", "instanceId")
|
|
65
|
+
.then(() => {
|
|
66
|
+
console.log("successful");
|
|
67
|
+
})
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
console.error("Error:", err);
|
|
70
|
+
});
|
|
49
71
|
```
|
|
50
72
|
|
|
51
|
-
|
|
73
|
+
```js
|
|
74
|
+
const ofs = require("ofsc-utility");
|
|
52
75
|
|
|
53
|
-
|
|
76
|
+
ofs
|
|
77
|
+
.downloadAllUsersCSV("clientId", "clientSecret", "instanceId")
|
|
78
|
+
.then(() => {
|
|
79
|
+
console.log("successful");
|
|
80
|
+
})
|
|
81
|
+
.catch((err) => {
|
|
82
|
+
console.error("Error:", err);
|
|
83
|
+
});
|
|
84
|
+
```
|
|
54
85
|
|
|
86
|
+
## License
|
|
55
87
|
|
|
88
|
+
MIT
|