ofsc-utility 1.0.5 → 1.0.7
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 +5 -0
- package/dist/index.js +10 -2
- package/dist/inventoryTypes/index.d.ts +4 -0
- package/dist/inventoryTypes/index.js +149 -0
- package/dist/types.d.ts +22 -0
- package/dist/workOrders/index.d.ts +0 -0
- package/dist/workOrders/index.js +1 -0
- package/package.json +2 -2
- package/readme.md +63 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * as InventoryType from './inventoryTypes';
|
|
1
2
|
export * as OauthTokenService from './oauthTokenService';
|
|
2
3
|
export * as Resource from './resources';
|
|
3
4
|
export * as User from './users';
|
|
@@ -7,10 +8,14 @@ export { getOAuthToken } from './oauthTokenService';
|
|
|
7
8
|
export { downloadWorkZoneCSV } from './workZones';
|
|
8
9
|
export { downloadAllResourcesCSV } from './resources';
|
|
9
10
|
export { downloadAllUsersCSV } from './users';
|
|
11
|
+
export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
|
|
10
12
|
declare const OfscUtility: {
|
|
11
13
|
getOAuthToken: any;
|
|
12
14
|
downloadWorkZoneCSV: any;
|
|
13
15
|
downloadAllResourcesCSV: any;
|
|
14
16
|
downloadAllUsersCSV: any;
|
|
17
|
+
downloadAllInventoryTypesCSV: any;
|
|
18
|
+
getInventoryTypesDetail: any;
|
|
19
|
+
updateInventoryType: any;
|
|
15
20
|
};
|
|
16
21
|
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.downloadAllUsersCSV = exports.downloadAllResourcesCSV = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.User = exports.Resource = exports.OauthTokenService = void 0;
|
|
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;
|
|
40
40
|
// Export all methods grouped by category
|
|
41
|
+
exports.InventoryType = __importStar(require("./inventoryTypes"));
|
|
41
42
|
exports.OauthTokenService = __importStar(require("./oauthTokenService"));
|
|
42
43
|
exports.Resource = __importStar(require("./resources"));
|
|
43
44
|
exports.User = __importStar(require("./users"));
|
|
@@ -53,12 +54,19 @@ var resources_1 = require("./resources");
|
|
|
53
54
|
Object.defineProperty(exports, "downloadAllResourcesCSV", { enumerable: true, get: function () { return resources_1.downloadAllResourcesCSV; } });
|
|
54
55
|
var users_1 = require("./users");
|
|
55
56
|
Object.defineProperty(exports, "downloadAllUsersCSV", { enumerable: true, get: function () { return users_1.downloadAllUsersCSV; } });
|
|
57
|
+
var inventoryTypes_1 = require("./inventoryTypes");
|
|
58
|
+
Object.defineProperty(exports, "downloadAllInventoryTypesCSV", { enumerable: true, get: function () { return inventoryTypes_1.downloadAllInventoryTypesCSV; } });
|
|
59
|
+
Object.defineProperty(exports, "getInventoryTypesDetail", { enumerable: true, get: function () { return inventoryTypes_1.getInventoryTypesDetail; } });
|
|
60
|
+
Object.defineProperty(exports, "updateCreateInventoryType", { enumerable: true, get: function () { return inventoryTypes_1.updateCreateInventoryType; } });
|
|
56
61
|
// Default export with all functionality
|
|
57
62
|
const OfscUtility = {
|
|
58
63
|
// Case converters
|
|
59
64
|
getOAuthToken: require('./oauthTokenService').getOAuthToken,
|
|
60
65
|
downloadWorkZoneCSV: require('./workZones').downloadWorkZoneCSV,
|
|
61
66
|
downloadAllResourcesCSV: require('./resources').downloadAllResourcesCSV,
|
|
62
|
-
downloadAllUsersCSV: require('./resources').downloadAllUsersCSV
|
|
67
|
+
downloadAllUsersCSV: require('./resources').downloadAllUsersCSV,
|
|
68
|
+
downloadAllInventoryTypesCSV: require('./inventoryTypes').downloadAllInventoryTypesCSV,
|
|
69
|
+
getInventoryTypesDetail: require('./inventoryTypes').getInventoryTypesDetail,
|
|
70
|
+
updateInventoryType: require('./inventoryTypes').updateInventoryType
|
|
63
71
|
};
|
|
64
72
|
exports.default = OfscUtility;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InventoryTypePayload, Response } from "../types";
|
|
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>;
|
|
@@ -0,0 +1,149 @@
|
|
|
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.downloadAllInventoryTypesCSV = downloadAllInventoryTypesCSV;
|
|
40
|
+
exports.getInventoryTypesDetail = getInventoryTypesDetail;
|
|
41
|
+
exports.updateCreateInventoryType = updateCreateInventoryType;
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
+
const index_1 = require("../oauthTokenService/index");
|
|
45
|
+
async function downloadAllInventoryTypesCSV(clientId, clientSecret, instanceUrl) {
|
|
46
|
+
let offset = 0;
|
|
47
|
+
const limit = 100;
|
|
48
|
+
let allItems = [];
|
|
49
|
+
let totalFetched = 0;
|
|
50
|
+
console.log("🚀 Starting all nventory type download...");
|
|
51
|
+
console.log("-------------------------------------");
|
|
52
|
+
while (true) {
|
|
53
|
+
const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscMetadata/v1/inventoryTypes/?offset=${offset}&limit=${limit}`;
|
|
54
|
+
const token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
|
|
55
|
+
console.log(`➡️ Fetching offset=${offset} limit=${limit}`);
|
|
56
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
57
|
+
method: "GET",
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: `Bearer ${token}`,
|
|
60
|
+
Accept: "application/json"
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (!res.ok) {
|
|
64
|
+
throw new Error(`❌ Fetch failed: ${res.status} ${res.statusText}`);
|
|
65
|
+
}
|
|
66
|
+
const data = (await res.json());
|
|
67
|
+
allItems.push(...data.items);
|
|
68
|
+
totalFetched += data.items.length;
|
|
69
|
+
console.log(` ✔ Received ${data.items.length} items (Total: ${totalFetched})`);
|
|
70
|
+
if (offset + limit >= data.totalResults)
|
|
71
|
+
break;
|
|
72
|
+
offset += limit;
|
|
73
|
+
}
|
|
74
|
+
console.log("-------------------------------------");
|
|
75
|
+
console.log("🧩 Collecting all unique properties...");
|
|
76
|
+
// Collect union of all properties
|
|
77
|
+
const allProperties = new Set();
|
|
78
|
+
for (const item of allItems) {
|
|
79
|
+
for (const key of Object.keys(item)) {
|
|
80
|
+
if (!["resources", "collaborationGroups", "resourceInternalIds", "links"].includes(key)) {
|
|
81
|
+
allProperties.add(key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const headers = Array.from(allProperties);
|
|
86
|
+
console.log(`📝 Total unique fields: ${headers.length}`);
|
|
87
|
+
// Build CSV rows
|
|
88
|
+
const csvRows = [];
|
|
89
|
+
csvRows.push(headers.join(","));
|
|
90
|
+
for (const item of allItems) {
|
|
91
|
+
const row = headers.map(field => {
|
|
92
|
+
let value = item[field];
|
|
93
|
+
if (field === "keys") {
|
|
94
|
+
if (Array.isArray(value))
|
|
95
|
+
return `"${value.join("|")}"`;
|
|
96
|
+
if (value)
|
|
97
|
+
return `"${String(value)}"`;
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
// Objects → JSON-safe string
|
|
101
|
+
if (typeof value === "object" && value !== null) {
|
|
102
|
+
return `"${JSON.stringify(value).replace(/"/g, "'")}"`;
|
|
103
|
+
}
|
|
104
|
+
return value !== undefined ? `"${String(value).replace(/"/g, "'")}"` : "";
|
|
105
|
+
});
|
|
106
|
+
csvRows.push(row.join(","));
|
|
107
|
+
}
|
|
108
|
+
const filePath = "./all_inventories.csv";
|
|
109
|
+
fs.writeFileSync(filePath, csvRows.join("\n"));
|
|
110
|
+
console.log("-------------------------------------");
|
|
111
|
+
console.log("✅ Inventories CSV Created Successfully!");
|
|
112
|
+
console.log(`📁 File: ${filePath}`);
|
|
113
|
+
console.log(`📦 Total Records: ${totalFetched}`);
|
|
114
|
+
console.log(`🧩 Total Columns (Dynamic): ${headers.length}`);
|
|
115
|
+
console.log(`🧩 Date Time: ${new Date()}`);
|
|
116
|
+
console.log("-------------------------------------");
|
|
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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A wrapper for Oracle Field Service REST API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
8
|
+
"build": "tsc && npm link",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"test:watch": "jest --watch",
|
package/readme.md
CHANGED
|
@@ -21,10 +21,20 @@ npm install ofsc-utility
|
|
|
21
21
|
|
|
22
22
|
### Download
|
|
23
23
|
|
|
24
|
+
#### csv
|
|
25
|
+
|
|
24
26
|
downloadWorkZoneCSV("clientId", "clientSecret", "instanceId")
|
|
25
27
|
downloadAllResourcesCSV("clientId", "clientSecret", "instanceId")
|
|
26
28
|
downloadAllUsersCSV("clientId", "clientSecret", "instanceId")
|
|
29
|
+
downloadAllInventoryTypesCSV("clientId", "clientSecret", "instanceId")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
#### records
|
|
33
|
+
|
|
27
34
|
getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
35
|
+
getInventoryTypesDetail("clientId", "clientSecret", "instanceId"."inventory_label")
|
|
36
|
+
|
|
37
|
+
|
|
28
38
|
|
|
29
39
|
## Usage
|
|
30
40
|
|
|
@@ -32,6 +42,18 @@ npm install ofsc-utility
|
|
|
32
42
|
|
|
33
43
|
### CommonJS
|
|
34
44
|
|
|
45
|
+
```js
|
|
46
|
+
|
|
47
|
+
async function run (){
|
|
48
|
+
let data = await ofs.InventoryType.getInventoryTypesDetail(
|
|
49
|
+
"clientId", "clientSecret", "instanceId", "inventory_label");
|
|
50
|
+
console.error(data);
|
|
51
|
+
}
|
|
52
|
+
run();
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
35
57
|
```js
|
|
36
58
|
const ofs = require("ofsc-utility");
|
|
37
59
|
|
|
@@ -83,6 +105,47 @@ ofs
|
|
|
83
105
|
});
|
|
84
106
|
```
|
|
85
107
|
|
|
108
|
+
```js
|
|
109
|
+
const ofs = require('ofsc-utility');
|
|
110
|
+
|
|
111
|
+
async function run() {
|
|
112
|
+
const payload = {
|
|
113
|
+
label: "inventory_label",
|
|
114
|
+
name: "Ordered Part",
|
|
115
|
+
unitOfMeasurement: "ea",
|
|
116
|
+
active: true,
|
|
117
|
+
nonSerialized: true,
|
|
118
|
+
modelProperty: "part_item_number_rev",
|
|
119
|
+
quantityPrecision: 0,
|
|
120
|
+
translations: [
|
|
121
|
+
{
|
|
122
|
+
language: "en",
|
|
123
|
+
name: "Ordered Part",
|
|
124
|
+
unitOfMeasurement: "ea",
|
|
125
|
+
languageISO: "en-US"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const result = await updateCreateInventoryType(
|
|
132
|
+
"CLIENT_ID",
|
|
133
|
+
"CLIENT_SECRET",
|
|
134
|
+
"INSTANCE_URL",
|
|
135
|
+
"inventory_label",
|
|
136
|
+
payload
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
console.log("Updated:", result);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(err);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
run();
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
|
|
86
149
|
## License
|
|
87
150
|
|
|
88
151
|
MIT
|