ofsc-utility 1.0.17 → 1.0.19
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/events/index.d.ts +9 -0
- package/dist/events/index.js +69 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +13 -2
- package/dist/metadata/activityTypeGroup.d.ts +4 -0
- package/dist/metadata/activityTypeGroup.js +45 -0
- package/dist/metadata/activityTypes.d.ts +3 -0
- package/dist/metadata/activityTypes.js +74 -0
- package/dist/metadata/applictaionsIntegration.d.ts +7 -0
- package/dist/metadata/applictaionsIntegration.js +81 -0
- package/dist/metadata/capacity.d.ts +4 -0
- package/dist/metadata/capacity.js +58 -0
- package/dist/metadata/capacityCategories.d.ts +4 -0
- package/dist/metadata/capacityCategories.js +48 -0
- package/dist/metadata/form.d.ts +4 -0
- package/dist/metadata/form.js +30 -0
- package/dist/metadata/index.d.ts +1 -0
- package/dist/metadata/index.js +78 -0
- package/dist/metadata/inventoryTypes.d.ts +4 -0
- package/dist/metadata/inventoryTypes.js +45 -0
- package/dist/metadata/languages.d.ts +4 -0
- package/dist/metadata/languages.js +33 -0
- package/dist/metadata/nonWorkingReasons.d.ts +4 -0
- package/dist/metadata/nonWorkingReasons.js +32 -0
- package/dist/metadata/properties.d.ts +4 -0
- package/dist/metadata/properties.js +45 -0
- package/dist/metadata/resourceTypes.d.ts +4 -0
- package/dist/metadata/resourceTypes.js +33 -0
- package/dist/metadata/shifts.d.ts +4 -0
- package/dist/metadata/shifts.js +35 -0
- package/dist/metadata/timeSlots.d.ts +4 -0
- package/dist/metadata/timeSlots.js +35 -0
- package/dist/metadata/workSkillConditions.d.ts +6 -0
- package/dist/metadata/workSkillConditions.js +87 -0
- package/dist/metadata/workSkills.d.ts +4 -0
- package/dist/metadata/workSkills.js +35 -0
- package/dist/metadata/workZoneKey.d.ts +4 -0
- package/dist/metadata/workZoneKey.js +44 -0
- package/dist/metadata/workZones.d.ts +4 -0
- package/dist/metadata/workZones.js +31 -0
- package/dist/resources/index.d.ts +5 -0
- package/dist/resources/index.js +27 -0
- package/dist/utilities/index.d.ts +15 -0
- package/dist/utilities/index.js +195 -0
- package/package.json +3 -1
- package/readme.md +5 -0
package/dist/utilities/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -6,6 +39,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
39
|
exports.fetchWithRetry = void 0;
|
|
7
40
|
exports.saveCsv = saveCsv;
|
|
8
41
|
exports.xmlNodeToObjects = xmlNodeToObjects;
|
|
42
|
+
exports.createExcelFile = createExcelFile;
|
|
43
|
+
exports.validateDateTimeStrict = validateDateTimeStrict;
|
|
44
|
+
exports.getTimeBefore180SecondsAlt = getTimeBefore180SecondsAlt;
|
|
45
|
+
const XLSX = __importStar(require("xlsx-js-style"));
|
|
9
46
|
const xmldom_1 = require("xmldom");
|
|
10
47
|
const oauthTokenService_1 = require("../oauthTokenService");
|
|
11
48
|
/**
|
|
@@ -115,3 +152,161 @@ function xmlNodeToObjects(xmlString, parentNodeName) {
|
|
|
115
152
|
return obj;
|
|
116
153
|
});
|
|
117
154
|
}
|
|
155
|
+
function createExcelFile(sheetsData, filename = 'file.xlsx') {
|
|
156
|
+
const workbook = XLSX.utils.book_new();
|
|
157
|
+
/* ============================
|
|
158
|
+
Create INDEX sheet first
|
|
159
|
+
============================ */
|
|
160
|
+
const indexData = Object.keys(sheetsData).map(sheetName => ({
|
|
161
|
+
"OFSC Master Configuration Sheet": sheetName
|
|
162
|
+
}));
|
|
163
|
+
const indexSheet = XLSX.utils.json_to_sheet(indexData);
|
|
164
|
+
// Style INDEX header
|
|
165
|
+
const indexHeaderCell = indexSheet['A1'];
|
|
166
|
+
if (indexHeaderCell) {
|
|
167
|
+
indexHeaderCell.s = {
|
|
168
|
+
fill: { fgColor: { rgb: 'FFD9D9D9' } },
|
|
169
|
+
font: { bold: true, size: 18 },
|
|
170
|
+
alignment: { horizontal: 'center' }
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// Add hyperlinks
|
|
174
|
+
indexData.forEach((_, i) => {
|
|
175
|
+
const row = i + 2; // data starts after header
|
|
176
|
+
const cellAddress = `A${row}`;
|
|
177
|
+
const cell = indexSheet[cellAddress];
|
|
178
|
+
if (cell) {
|
|
179
|
+
cell.l = {
|
|
180
|
+
Target: `#'${cell.v}'!A1`,
|
|
181
|
+
Tooltip: `Go to ${cell.v}`
|
|
182
|
+
};
|
|
183
|
+
cell.s = {
|
|
184
|
+
font: {
|
|
185
|
+
color: { rgb: 'FF0563C1' }, // Excel hyperlink blue
|
|
186
|
+
underline: true
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
indexSheet['!cols'] = [{ wch: 30 }];
|
|
192
|
+
XLSX.utils.book_append_sheet(workbook, indexSheet, 'INDEX');
|
|
193
|
+
/* ============================
|
|
194
|
+
Create data sheets
|
|
195
|
+
============================ */
|
|
196
|
+
Object.entries(sheetsData).forEach(([sheetName, data]) => {
|
|
197
|
+
const worksheet = XLSX.utils.json_to_sheet(data);
|
|
198
|
+
if (data.length > 0) {
|
|
199
|
+
const keys = Object.keys(data[0]);
|
|
200
|
+
// Auto-size columns
|
|
201
|
+
worksheet['!cols'] = keys.map(key => {
|
|
202
|
+
const maxLength = Math.max(key.length, ...data.map(row => String(row[key] ?? '').length));
|
|
203
|
+
return { wch: Math.min(maxLength + 2, 50) };
|
|
204
|
+
});
|
|
205
|
+
// Highlight header row
|
|
206
|
+
keys.forEach((_, colIndex) => {
|
|
207
|
+
const addr = XLSX.utils.encode_cell({ r: 0, c: colIndex });
|
|
208
|
+
const cell = worksheet[addr];
|
|
209
|
+
if (!cell)
|
|
210
|
+
return;
|
|
211
|
+
cell.s = {
|
|
212
|
+
fill: { fgColor: { rgb: 'FFD9D9D9' } },
|
|
213
|
+
font: { bold: false, sz: 14, },
|
|
214
|
+
alignment: { horizontal: 'center' }
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
// Process data rows
|
|
218
|
+
data.forEach((row, rowIndex) => {
|
|
219
|
+
const rowIsInactive = row.Status === 'Inactive' ||
|
|
220
|
+
JSON.stringify(row).toUpperCase().includes('INACTIVE') || JSON.stringify(row).toUpperCase().includes('INACTIVATE');
|
|
221
|
+
keys.forEach((key, colIndex) => {
|
|
222
|
+
const addr = XLSX.utils.encode_cell({
|
|
223
|
+
r: rowIndex + 1,
|
|
224
|
+
c: colIndex
|
|
225
|
+
});
|
|
226
|
+
const cell = worksheet[addr];
|
|
227
|
+
if (!cell)
|
|
228
|
+
return;
|
|
229
|
+
const value = String(row[key] ?? '').toLowerCase();
|
|
230
|
+
cell.s = cell.s || {};
|
|
231
|
+
// "read write" highlight
|
|
232
|
+
if (value.includes('read write')) {
|
|
233
|
+
cell.s.font = {
|
|
234
|
+
...(cell.s.font || {}),
|
|
235
|
+
bold: true,
|
|
236
|
+
color: { rgb: 'FFCC0000' }
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (value.includes('nonserialized')) {
|
|
240
|
+
cell.s.font = {
|
|
241
|
+
...(cell.s.font || {}),
|
|
242
|
+
bold: true,
|
|
243
|
+
color: { rgb: 'FF006100' }
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (value.includes('it is being used')) {
|
|
247
|
+
cell.s.font = {
|
|
248
|
+
...(cell.s.font || {}),
|
|
249
|
+
bold: true,
|
|
250
|
+
color: { rgb: 'FF006100' }
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (value.includes('on-call')) {
|
|
254
|
+
cell.s.font = {
|
|
255
|
+
...(cell.s.font || {}),
|
|
256
|
+
bold: true,
|
|
257
|
+
color: { rgb: 'FF0563C1' }
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
// Inactive row highlight
|
|
261
|
+
if (rowIsInactive) {
|
|
262
|
+
cell.s.fill = { fgColor: { rgb: 'FFFFCCCC' } };
|
|
263
|
+
cell.s.font = {
|
|
264
|
+
...(cell.s.font || {}),
|
|
265
|
+
color: { rgb: 'FFCC0000' }
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
272
|
+
});
|
|
273
|
+
XLSX.writeFile(workbook, filename);
|
|
274
|
+
console.log(`✓ Excel file created: ${filename}`);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Validate Date String Format must be YYYY-MM-DD HH:MM:SS
|
|
278
|
+
* @param dateTimeStr :string
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
function validateDateTimeStrict(dateTimeStr) {
|
|
282
|
+
const regex = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
|
|
283
|
+
const match = dateTimeStr.match(regex);
|
|
284
|
+
if (!match) {
|
|
285
|
+
return { isValid: false, error: 'Format must be YYYY-MM-DD HH:MM:SS' };
|
|
286
|
+
}
|
|
287
|
+
const [, year, month, day, hours, minutes, seconds] = match.map(Number);
|
|
288
|
+
if (month < 1 || month > 12) {
|
|
289
|
+
return { isValid: false, error: 'Month must be between 1 and 12' };
|
|
290
|
+
}
|
|
291
|
+
const daysInMonth = new Date(year, month, 0).getDate();
|
|
292
|
+
if (day < 1 || day > daysInMonth) {
|
|
293
|
+
return { isValid: false, error: `Day must be between 1 and ${daysInMonth}` };
|
|
294
|
+
}
|
|
295
|
+
if (hours < 0 || hours > 23) {
|
|
296
|
+
return { isValid: false, error: 'Hours must be between 0 and 23' };
|
|
297
|
+
}
|
|
298
|
+
if (minutes < 0 || minutes > 59) {
|
|
299
|
+
return { isValid: false, error: 'Minutes must be between 0 and 59' };
|
|
300
|
+
}
|
|
301
|
+
if (seconds < 0 || seconds > 59) {
|
|
302
|
+
return { isValid: false, error: 'Seconds must be between 0 and 59' };
|
|
303
|
+
}
|
|
304
|
+
return { isValid: true };
|
|
305
|
+
}
|
|
306
|
+
function getTimeBefore180SecondsAlt() {
|
|
307
|
+
const timeBefore = new Date(Date.now() - 180000); // 180 * 1000 = 180000
|
|
308
|
+
// Convert to ISO string and format
|
|
309
|
+
return timeBefore.toISOString()
|
|
310
|
+
.replace('T', ' ')
|
|
311
|
+
.substring(0, 19);
|
|
312
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ofsc-utility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "A wrapper for Oracle Field Service REST API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"node-fetch": "^2.7.0",
|
|
49
49
|
"tslib": "^2.8.1",
|
|
50
|
+
"xlsx": "^0.18.5",
|
|
51
|
+
"xlsx-js-style": "^1.2.0",
|
|
50
52
|
"xmldom": "^0.6.0"
|
|
51
53
|
}
|
|
52
54
|
}
|
package/readme.md
CHANGED
|
@@ -46,6 +46,11 @@ Please see the code snippet below.
|
|
|
46
46
|
downloadAllEventsOfDay(process.env.clientID, process.env.clientSecret, process.env.instanceId, process.env.subscriptionId,"2025-12-05")
|
|
47
47
|
getActivitybyId("clientId", "clientSecret", "instanceId"."activityId")
|
|
48
48
|
|
|
49
|
+
### Technical Design Doc - Configurations
|
|
50
|
+
|
|
51
|
+
// It will create a techncial configuration file
|
|
52
|
+
createConfigurationFile(process.env.clientID, process.env.clientSecreat,process.env.instanceId,"OFSC_CONFIGURATION_SHEET.xlsx")
|
|
53
|
+
|
|
49
54
|
## Usage
|
|
50
55
|
|
|
51
56
|
downloadWorkZoneCSV("bot", "XXXXXXXXX", "compXXX.test")
|