ofsc-utility 1.0.56 → 1.0.58

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/CHANGELOG.md CHANGED
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
14
14
  - version 1.0.46
15
15
 
16
16
  ### Added
17
+ - add getAllScheduledActivities for OFSC activities and bump version to 1.0.56
17
18
  - add getAllNonScheduledActivities function
18
19
  - Bump version to 1.0.52 and add activity lifecycle actions
19
20
  - update version to 1.0.51 and add user/inventory type management functions
@@ -135,6 +135,7 @@ async function getAllScheduledActivities(clientId, clientSecret, instanceUrl, ro
135
135
  dateFrom: dateFromStr,
136
136
  dateTo: dateToStr,
137
137
  includeNonScheduled: "false",
138
+ fields: "status,activityId,activityType,date,resourceId,customerName"
138
139
  });
139
140
  if (rootBucket) {
140
141
  params.append("resources", rootBucket);
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export { generateAllOnHandInventoryOfAllResources, generateAllOnHandInventoryOfA
14
14
  export { getOAuthToken } from './oauthTokenService';
15
15
  export { downloadWorkZoneCSV } from './workZones';
16
16
  export { AllResources, downloadAllResourcesCSV, getResourcebyId, getworkSkillsOfResource, updateResourcebyId } from './resources';
17
- export { downloadAllInactiveUsers, downloadAllInactiveUsersCSV, downloadAllUsersCSV, generateUsersCollaborationCSV, getUserByLogin, updateUserbyLogin } from './users';
17
+ export { downloadAllInactiveUsers, downloadAllInactiveUsersCSV, downloadAllUsersCSV, generateUsersCollaborationCSV, getUserByLogin, updateUserbyLogin, downloadAllUsers } from './users';
18
18
  export { downloadAllInventoryTypesCSV, getInventoryTypesDetail, updateCreateInventoryType } from './inventoryTypes';
19
19
  export { getActivitybyId, getAllActivities, getAllScheduledActivities, startActivity, cancelActivity, completeActivity, deleteActivity, getAllNonScheduledActivities } from './activities';
20
20
  export { createActivityCustomerInventories, getActivityCustomerInventories } from './activityInventories';
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.downloadAllEventsOfLastOneHour = exports.downloadAllEventsOfDLastTwoMinutes = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllNonScheduledActivities = exports.deleteActivity = exports.completeActivity = exports.cancelActivity = exports.startActivity = exports.getAllScheduledActivities = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.updateUserbyLogin = exports.getUserByLogin = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = exports.updateResourcebyId = exports.getworkSkillsOfResource = exports.getResourcebyId = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = exports.generateAllOnHandInventoryOfAllResources = 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.downloadAllEventsOfDLastTwoMinutes = exports.downloadAllEventsOfDayCSV = exports.downloadAllEventsOfDay = exports.getActivityCustomerInventories = exports.createActivityCustomerInventories = exports.getAllNonScheduledActivities = exports.deleteActivity = exports.completeActivity = exports.cancelActivity = exports.startActivity = exports.getAllScheduledActivities = exports.getAllActivities = exports.getActivitybyId = exports.updateCreateInventoryType = exports.getInventoryTypesDetail = exports.downloadAllInventoryTypesCSV = exports.downloadAllUsers = exports.updateUserbyLogin = exports.getUserByLogin = exports.generateUsersCollaborationCSV = exports.downloadAllUsersCSV = exports.downloadAllInactiveUsersCSV = exports.downloadAllInactiveUsers = exports.updateResourcebyId = exports.getworkSkillsOfResource = exports.getResourcebyId = exports.downloadAllResourcesCSV = exports.AllResources = exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.generateAllOnHandInventoryOfAllResourcesCSV = exports.generateAllOnHandInventoryOfAllResources = 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"));
@@ -71,6 +71,7 @@ Object.defineProperty(exports, "downloadAllUsersCSV", { enumerable: true, get: f
71
71
  Object.defineProperty(exports, "generateUsersCollaborationCSV", { enumerable: true, get: function () { return users_1.generateUsersCollaborationCSV; } });
72
72
  Object.defineProperty(exports, "getUserByLogin", { enumerable: true, get: function () { return users_1.getUserByLogin; } });
73
73
  Object.defineProperty(exports, "updateUserbyLogin", { enumerable: true, get: function () { return users_1.updateUserbyLogin; } });
74
+ Object.defineProperty(exports, "downloadAllUsers", { enumerable: true, get: function () { return users_1.downloadAllUsers; } });
74
75
  var inventoryTypes_1 = require("./inventoryTypes");
75
76
  Object.defineProperty(exports, "downloadAllInventoryTypesCSV", { enumerable: true, get: function () { return inventoryTypes_1.downloadAllInventoryTypesCSV; } });
76
77
  Object.defineProperty(exports, "getInventoryTypesDetail", { enumerable: true, get: function () { return inventoryTypes_1.getInventoryTypesDetail; } });
@@ -1,5 +1,6 @@
1
1
  import { ResourceResponse } from "../types";
2
2
  export declare function downloadAllUsersCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
3
+ export declare function downloadAllUsers(clientId: string, clientSecret: string, instanceUrl: string): Promise<any[]>;
3
4
  export { generateUsersCollaborationCSV } from './collaborationGroups';
4
5
  declare const OfscUserUtility: {
5
6
  generateUsersCollaborationCSV: any;
@@ -7,6 +8,7 @@ declare const OfscUserUtility: {
7
8
  downloadAllInactiveUsersCSV: typeof downloadAllInactiveUsersCSV;
8
9
  downloadAllInactiveUsers: typeof downloadAllInactiveUsers;
9
10
  getUserByLogin: typeof getUserByLogin;
11
+ downloadAllUsers: typeof downloadAllUsers;
10
12
  };
11
13
  export declare function downloadAllInactiveUsersCSV(clientId: string, clientSecret: string, instanceUrl: string, inactivityThresholdDays?: number): Promise<void>;
12
14
  export declare function downloadAllInactiveUsers(clientId: string, clientSecret: string, instanceUrl: string, inactivityThresholdDays?: number): Promise<Record<string, any>[]>;
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.generateUsersCollaborationCSV = void 0;
40
40
  exports.downloadAllUsersCSV = downloadAllUsersCSV;
41
+ exports.downloadAllUsers = downloadAllUsers;
41
42
  exports.downloadAllInactiveUsersCSV = downloadAllInactiveUsersCSV;
42
43
  exports.downloadAllInactiveUsers = downloadAllInactiveUsers;
43
44
  exports.getUserByLogin = getUserByLogin;
@@ -119,6 +120,37 @@ async function downloadAllUsersCSV(clientId, clientSecret, instanceUrl) {
119
120
  console.log(`Date Time: ${new Date()}`);
120
121
  console.log("-------------------------------------");
121
122
  }
123
+ async function downloadAllUsers(clientId, clientSecret, instanceUrl) {
124
+ let offset = 0;
125
+ const limit = 100;
126
+ let allItems = [];
127
+ let totalFetched = 0;
128
+ console.log("Starting users download...");
129
+ console.log("-------------------------------------");
130
+ while (true) {
131
+ const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscCore/v1/users/?offset=${offset}&limit=${limit}`;
132
+ const token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
133
+ console.log(`Fetching offset=${offset} limit=${limit}`);
134
+ const res = await (0, node_fetch_1.default)(url, {
135
+ method: "GET",
136
+ headers: {
137
+ Authorization: `Bearer ${token}`,
138
+ Accept: "application/json"
139
+ }
140
+ });
141
+ if (!res.ok) {
142
+ throw new Error(`Fetch failed: ${res.status} ${res.statusText}`);
143
+ }
144
+ const data = (await res.json());
145
+ allItems.push(...data.items);
146
+ totalFetched += data.items.length;
147
+ console.log(` Received ${data.items.length} items (Total: ${totalFetched})`);
148
+ if (offset + limit >= data.totalResults)
149
+ break;
150
+ offset += limit;
151
+ }
152
+ return allItems;
153
+ }
122
154
  var collaborationGroups_1 = require("./collaborationGroups");
123
155
  Object.defineProperty(exports, "generateUsersCollaborationCSV", { enumerable: true, get: function () { return collaborationGroups_1.generateUsersCollaborationCSV; } });
124
156
  const OfscUserUtility = {
@@ -126,7 +158,8 @@ const OfscUserUtility = {
126
158
  downloadAllUsersCSV,
127
159
  downloadAllInactiveUsersCSV,
128
160
  downloadAllInactiveUsers,
129
- getUserByLogin
161
+ getUserByLogin,
162
+ downloadAllUsers
130
163
  };
131
164
  /**
132
165
  * Returns true if the user is "inactive":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsc-utility",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "TypeScript helpers for Oracle Field Service Cloud (OFSC): events, resources, inventories, metadata and CSV/Excel utilities.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -117,6 +117,7 @@ The package exposes both top-level helpers and grouped namespaces. This list is
117
117
  - `getResourcebyId`
118
118
  - `getworkSkillsOfResource`
119
119
  - `updateResourcebyId`
120
+ - `downloadAllUsers`
120
121
  - `downloadAllUsersCSV`
121
122
  - `downloadAllInactiveUsersCSV`
122
123
  - `downloadAllInactiveUsers`
@@ -182,6 +183,7 @@ The module-level namespace exports are:
182
183
  - `getworkSkillsOfResource`
183
184
  - `updateResourcebyId`
184
185
  - `ofs.User`
186
+ - `downloadAllUsers`
185
187
  - `downloadAllUsersCSV`
186
188
  - `downloadAllInactiveUsersCSV`
187
189
  - `downloadAllInactiveUsers`
@@ -473,6 +475,75 @@ console.log("Resource:", resource);
473
475
  console.log("Work skills:", workSkills.data);
474
476
  ```
475
477
 
478
+ #### Download all users
479
+
480
+ `downloadAllUsers` retrieves every user from the OFSC Users API and returns the
481
+ results as an array of plain objects. The method automatically follows the API
482
+ pagination and does not create a CSV file.
483
+
484
+ ```js
485
+ const ofs = require("ofsc-utility");
486
+
487
+ async function downloadUsers() {
488
+ const users = await ofs.downloadAllUsers(
489
+ process.env.CLIENT_ID,
490
+ process.env.CLIENT_SECRET,
491
+ process.env.INSTANCE_URL,
492
+ );
493
+
494
+ console.log(`Downloaded ${users.length} users.`);
495
+ console.log(users[0]);
496
+ }
497
+
498
+ downloadUsers().catch((error) => {
499
+ console.error("Failed to download users:", error);
500
+ process.exit(1);
501
+ });
502
+ ```
503
+
504
+ Or, use the grouped namespace:
505
+
506
+ ```js
507
+ const users = await ofs.User.downloadAllUsers(
508
+ process.env.CLIENT_ID,
509
+ process.env.CLIENT_SECRET,
510
+ process.env.INSTANCE_URL,
511
+ );
512
+ ```
513
+
514
+ **Function signature**
515
+
516
+ ```ts
517
+ downloadAllUsers(
518
+ clientId: string,
519
+ clientSecret: string,
520
+ instanceUrl: string,
521
+ ): Promise<any[]>
522
+ ```
523
+
524
+ **Parameters and result**
525
+
526
+ - `clientId`: OFSC OAuth client ID.
527
+ - `clientSecret`: OFSC OAuth client secret.
528
+ - `instanceUrl`: OFSC instance name only, such as `mycompany`. Do not include
529
+ `https://` or `.fs.ocs.oraclecloud.com`.
530
+ - The returned array contains every user returned by the API pages. Each user is
531
+ represented as a plain object.
532
+
533
+ The helper retrieves users in pages of 100 records and requires valid OFSC API
534
+ credentials. It obtains an OAuth token for each page and returns the combined
535
+ results after the final page is reached.
536
+
537
+ To run the repository test script against a built distribution:
538
+
539
+ ```bash
540
+ npm run build
541
+ export CLIENT_ID=yourClientId
542
+ export CLIENT_SECRET=yourClientSecret
543
+ export INSTANCE_URL=yourInstanceName
544
+ node scripts/test-download-all-users.js
545
+ ```
546
+
476
547
  #### Download inactive users
477
548
 
478
549
  `downloadAllInactiveUsersCSV` downloads all users from the OFSC Users API, filters