ofsc-utility 1.0.30 → 1.0.32

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.
@@ -56,4 +56,13 @@ export declare function generateHash(item: {
56
56
  * @returns
57
57
  */
58
58
  export declare function downloadAllEventsOfDLastTwoMinutes(clientId: string, clientSecret: string, instanceUrl: string, subscriptionId: string): Promise<any[]>;
59
+ /**
60
+ * Events of last one hour
61
+ * @param clientId
62
+ * @param clientSecret
63
+ * @param instanceUrl
64
+ * @param subscriptionId
65
+ * @returns
66
+ */
67
+ export declare function downloadAllEventsOfLastOneHour(clientId: string, clientSecret: string, instanceUrl: string, subscriptionId: string): Promise<any[]>;
59
68
  export {};
@@ -8,6 +8,7 @@ exports.downloadAllEventsOfDay = downloadAllEventsOfDay;
8
8
  exports.downloadAllEventsOfDayCSV = downloadAllEventsOfDayCSV;
9
9
  exports.generateHash = generateHash;
10
10
  exports.downloadAllEventsOfDLastTwoMinutes = downloadAllEventsOfDLastTwoMinutes;
11
+ exports.downloadAllEventsOfLastOneHour = downloadAllEventsOfLastOneHour;
11
12
  const node_crypto_1 = __importDefault(require("node:crypto"));
12
13
  const path_1 = __importDefault(require("path"));
13
14
  const index_1 = require("../oauthTokenService/index");
@@ -363,3 +364,92 @@ async function downloadAllEventsOfDLastTwoMinutes(clientId, clientSecret, instan
363
364
  }
364
365
  return events;
365
366
  }
367
+ /**
368
+ * Events of last one hour
369
+ * @param clientId
370
+ * @param clientSecret
371
+ * @param instanceUrl
372
+ * @param subscriptionId
373
+ * @returns
374
+ */
375
+ async function downloadAllEventsOfLastOneHour(clientId, clientSecret, instanceUrl, subscriptionId) {
376
+ /**
377
+ * Download events from the last ~180 seconds and return them as an
378
+ * array.
379
+ *
380
+ * Differences from `downloadAllEventsOfDayCSV`:
381
+ * - The `since` timestamp is computed using `getTimeBefore180SecondsAlt`.
382
+ * - Validates the generated timestamp with `validateDateTimeStrict`.
383
+ * - For each fetched item, this function attaches a `uniqueId` field
384
+ * generated by `generateHash` (used for deduplication or tracing).
385
+ *
386
+ * Usage: lightweight polling helper to retrieve recent events for
387
+ * short-lived processing or monitoring.
388
+ *
389
+ * @param clientId - OAuth client id.
390
+ * @param clientSecret - OAuth client secret.
391
+ * @param instanceUrl - Instance host.
392
+ * @param subscriptionId - Subscription id for events.
393
+ * @returns Array of recent event objects.
394
+ */
395
+ // All collected events
396
+ const events = [];
397
+ const since = (0, utilities_1.getTimeBefore3600SecondsAlt)();
398
+ let isValidate = (0, index_2.validateDateTimeStrict)(since);
399
+ if (!isValidate.isValid) {
400
+ throw new Error(isValidate.error);
401
+ }
402
+ // Build initial request URL
403
+ const baseUrl = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/events`;
404
+ const initialUrl = `${baseUrl}?subscriptionId=${encodeURIComponent(subscriptionId)}&since=${encodeURIComponent(since)}`;
405
+ console.log("sinceDate", since);
406
+ let token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
407
+ // Get first page
408
+ let firstPage = await fetchEventsPage(initialUrl, token, clientId, clientSecret, instanceUrl);
409
+ token = firstPage.token;
410
+ let nextPage = firstPage.data.nextPage;
411
+ let found = firstPage.data.found;
412
+ // Controls infinite loop
413
+ let lastSeenPage = nextPage;
414
+ let repeatedPageCount = 0;
415
+ // Loop through pages
416
+ while (found && nextPage) {
417
+ const pageUrl = new URL(baseUrl);
418
+ pageUrl.search = new URLSearchParams({
419
+ subscriptionId,
420
+ page: nextPage,
421
+ limit: "1000",
422
+ }).toString();
423
+ const finalUrl = pageUrl.toString();
424
+ const result = await fetchEventsPage(finalUrl, token, clientId, clientSecret, instanceUrl);
425
+ token = result.token;
426
+ const page = result.data;
427
+ found = page.found;
428
+ nextPage = page.nextPage;
429
+ console.error("nextPage", nextPage, "Records:", page.items?.length, "Time:", page.items?.[0]?.time);
430
+ // Prevent infinite looping
431
+ if (nextPage === lastSeenPage) {
432
+ repeatedPageCount++;
433
+ if (repeatedPageCount > 15) {
434
+ console.warn("⚠️ Pagination repeating same page more than 15 times. Stopping.");
435
+ break;
436
+ }
437
+ }
438
+ else {
439
+ lastSeenPage = nextPage;
440
+ repeatedPageCount = 0;
441
+ }
442
+ // Add events
443
+ if (!page.items) {
444
+ console.warn("⚠️ No items found in page. Stopping.");
445
+ break;
446
+ }
447
+ for (let k of page.items) {
448
+ k["uniqueId"] = generateHash(k);
449
+ k["Change"] = k.activityChanges || k.inventoryChanges || k.requestChanges || k.userChanges || {};
450
+ k["Id"] = k.activityDetails?.activityId || k.resourceDetails?.resourceId || `${k.userDetails?.login}(${k.userDetails?.status})` || '-';
451
+ events.push(k);
452
+ }
453
+ }
454
+ return events;
455
+ }
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ export { downloadAllUsersCSV, generateUsersCollaborationCSV } from './users';
18
18
  export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
19
19
  export { getActivitybyId, getAllActivities } from './activities';
20
20
  export { createActivityCustomerInventories, getActivityCustomerInventories } from './activityInventories';
21
- export { downloadAllEventsOfDay, downloadAllEventsOfDayCSV } from './events';
21
+ export { downloadAllEventsOfDay, downloadAllEventsOfDayCSV, downloadAllEventsOfLastOneHour } from './events';
22
22
  export { createExcelFile } from './utilities';
23
23
  export { createConfigurationFile } from './metadata';
24
24
  declare const OfscUtility: {
@@ -50,6 +50,7 @@ declare const OfscUtility: {
50
50
  };
51
51
  downloadAllEventsOfDayCSV: any;
52
52
  downloadAllEventsOfDay: any;
53
+ downloadAllEventsOfLastOneHour: any;
53
54
  generateUsersCollaborationCSV: any;
54
55
  generateAllOnHandInventoryOfAllResourcesCSV: any;
55
56
  getActivitybyId: any;
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ 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.createConfigurationFile = exports.createExcelFile = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.getworkSkillsOfResource = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = exports.WorkZone = exports.Utilities = exports.User = exports.Resource = exports.OauthTokenService = exports.CreateConfigurationFile = exports.InventoryType = exports.Inventory = exports.Events = exports.ActivityInventories = exports.Activity = void 0;
39
+ exports.createConfigurationFile = exports.createExcelFile = exports.downloadAllEventsOfLastOneHour = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.getworkSkillsOfResource = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = exports.WorkZone = exports.Utilities = exports.User = exports.Resource = exports.OauthTokenService = exports.CreateConfigurationFile = exports.InventoryType = exports.Inventory = exports.Events = exports.ActivityInventories = exports.Activity = void 0;
40
40
  // Export all methods grouped by category
41
41
  exports.Activity = __importStar(require("./activities"));
42
42
  exports.ActivityInventories = __importStar(require("./activityInventories"));
@@ -77,6 +77,7 @@ Object.defineProperty(exports, "getActivityCustomerInventories", { enumerable: t
77
77
  var events_1 = require("./events");
78
78
  Object.defineProperty(exports, "downloadAllEventsOfDay", { enumerable: true, get: function () { return events_1.downloadAllEventsOfDay; } });
79
79
  Object.defineProperty(exports, "downloadAllEventsOfDayCSV", { enumerable: true, get: function () { return events_1.downloadAllEventsOfDayCSV; } });
80
+ Object.defineProperty(exports, "downloadAllEventsOfLastOneHour", { enumerable: true, get: function () { return events_1.downloadAllEventsOfLastOneHour; } });
80
81
  var utilities_1 = require("./utilities");
81
82
  Object.defineProperty(exports, "createExcelFile", { enumerable: true, get: function () { return utilities_1.createExcelFile; } });
82
83
  var metadata_1 = require("./metadata");
@@ -111,6 +112,7 @@ const OfscUtility = {
111
112
  },
112
113
  downloadAllEventsOfDayCSV: require('./events').downloadAllEventsOfDayCSV,
113
114
  downloadAllEventsOfDay: require('./events').downloadAllEventsOfDay,
115
+ downloadAllEventsOfLastOneHour: require('./events').downloadAllEventsOfLastOneHour,
114
116
  generateUsersCollaborationCSV: require('./users').generateUsersCollaborationCSV,
115
117
  generateAllOnHandInventoryOfAllResourcesCSV: require('./inventory').generateAllOnHandInventoryOfAllResourcesCSV,
116
118
  getActivitybyId: require('./activities').getActivitybyId,
@@ -29,4 +29,5 @@ interface ValidationResult {
29
29
  */
30
30
  export declare function validateDateTimeStrict(dateTimeStr: string): ValidationResult;
31
31
  export declare function getTimeBefore180SecondsAlt(): string;
32
+ export declare function getTimeBefore3600SecondsAlt(): string;
32
33
  export {};
@@ -42,6 +42,7 @@ exports.xmlNodeToObjects = xmlNodeToObjects;
42
42
  exports.createExcelFile = createExcelFile;
43
43
  exports.validateDateTimeStrict = validateDateTimeStrict;
44
44
  exports.getTimeBefore180SecondsAlt = getTimeBefore180SecondsAlt;
45
+ exports.getTimeBefore3600SecondsAlt = getTimeBefore3600SecondsAlt;
45
46
  const XLSX = __importStar(require("xlsx-js-style"));
46
47
  const xmldom_1 = require("xmldom");
47
48
  const oauthTokenService_1 = require("../oauthTokenService");
@@ -76,7 +77,7 @@ const fetchWithRetry = async (url, clientId, clientSecret, instanceUrl, token, r
76
77
  res = await doFetch(token);
77
78
  }
78
79
  /* ---------- 429: retry with backoff ---------- */
79
- if (res.status === 429 && retries > 0) {
80
+ if ((res.status === 429 || res.status === 400) && retries > 0) {
80
81
  const retryAfter = res.headers.get("Retry-After");
81
82
  console.log("⚠️ 429 received. Retrying...", retryAfter);
82
83
  const delay = retryAfter ? Number(retryAfter) * 1000 : baseDelay;
@@ -310,3 +311,10 @@ function getTimeBefore180SecondsAlt() {
310
311
  .replace('T', ' ')
311
312
  .substring(0, 19);
312
313
  }
314
+ function getTimeBefore3600SecondsAlt() {
315
+ const timeBefore = new Date(Date.now() - 3600000); // 3600 * 1000 = 3600000
316
+ // Convert to ISO string and format
317
+ return timeBefore.toISOString()
318
+ .replace('T', ' ')
319
+ .substring(0, 19);
320
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsc-utility",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "A wrapper for Oracle Field Service REST API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -282,6 +282,29 @@ The `metadata` object exposes metadata helpers such as:
282
282
  - `getWorkZonesMetaData`
283
283
  - `createConfigurationFile`
284
284
 
285
+ ### Properties metadata note
286
+
287
+ The `getPropertiesMetaData` helper fetches OFSC property definitions and then builds:
288
+
289
+ - `Properties Overview`: one row per property, including label, name, type, entity, GUI, clone flag, and deduplicated comments
290
+ - `Properties Enumerations`: combined enumeration dropdown values for any properties whose data type is `enumeration`
291
+
292
+ This function requires an `allUsedPropes` array to identify which properties are referenced by other metadata types and to collect comments for the overview.
293
+
294
+ ```js
295
+ const allPropes = [];
296
+
297
+ const propertiesSheet = await ofs.metadata.getPropertiesMetaData(
298
+ process.env.CLIENT_ID,
299
+ process.env.CLIENT_SECRET,
300
+ process.env.INSTANCE_NAME,
301
+ allPropes,
302
+ );
303
+
304
+ console.log(propertiesSheet["Properties Overview"]);
305
+ console.log(propertiesSheet["Properties Enumerations"]);
306
+ ```
307
+
285
308
  ## Notes
286
309
 
287
310
  - `instanceUrl` is the OFSC instance name only, not the full URL. For example: `mycompany` for `mycompany.fs.ocs.oraclecloud.com`.