ofsc-utility
v1.0.61
Published
TypeScript helpers for Oracle Field Service Cloud (OFSC): events, resources, inventories, metadata and CSV/Excel utilities.
Maintainers
Readme
OFSC Utility
A small TypeScript wrapper for Oracle Field Service Cloud (OFSC) REST APIs.
This package exposes grouped API helpers for common OFSC operations, including:
- authentication
- export/download helpers
- inventory and activity records
- metadata file generation
- user and resource operations for standalone OFSC environments
Note: User and resource-related methods are applicable exclusively to standalone OFSC environments and are not supported in Fusion OFSC.
This library is intended for OFSC integrations where the standard OFSC REST APIs are available. The user and resource-related methods are designed for standalone OFSC deployments and should not be relied on for Fusion OFSC environments, where the underlying APIs and behavior can differ.
Built-in resilience for OFSC's server errors
OFSC's REST API sits behind Oracle's gateway infrastructure, which means calls can occasionally fail with transient errors that have nothing to do with your request — the gateway losing its connection to the backend, a brief service restart, or normal rate limiting under load. This package handles those cases automatically so your integration doesn't fail on a blip that would have succeeded a second later.
Exponential backoff
Retries don't hammer the API at a fixed interval — each attempt waits longer than the last (starting at a small base delay and doubling each time), unless OFSC explicitly tells us how long to wait via Retry-After. This gives Oracle's backend room to recover instead of adding to the load that likely caused the error in the first place.
Why this matters for OFSC specifically
OFSC's gateway is known to return 503s and connection resets during normal operation — not just outages — especially under sustained polling or bulk export workloads (events, activities, inventory).Handling these transparently means:
- Scheduled jobs don't die on a single flaky response and require manual re-runs
- Token expiry mid-session is handled without the caller needing to track token lifetimes
- You get clear, real error messages (with the response body attached) for genuine failures, instead of noisy retries on errors that were never going to succeed
Installation
npm install ofsc-utility@latestGetting Started
- Install the package:
npm install ofsc-utility- Create a
.envfile or export environment variables in your shell:
export CLIENT_ID=yourClientId
export CLIENT_SECRET=yourClientSecret
export INSTANCE_NAME=yourInstanceName
export SUBSCRIPTION_ID=yourSubscriptionIdinstanceUrlis the OFSC instance name only, not the full URL. For example:mycompanyformycompany.fs.ocs.oraclecloud.com.
Create a file such as
example.jsand add the sample code below.Run the example:
node example.jsQuick Start
CommonJS
const ofs = require("ofsc-utility");
async function main() {
const token = await ofs.getOAuthToken(
"CLIENT_ID",
"CLIENT_SECRET",
"INSTANCE_NAME",
);
console.log("OAuth token:", token);
}
main().catch(console.error);ES Modules
import ofs from "ofsc-utility";
async function main() {
const token = await ofs.getOAuthToken(
"CLIENT_ID",
"CLIENT_SECRET",
"INSTANCE_NAME",
);
console.log("OAuth token:", token);
}
main().catch(console.error);Available exports
The package exposes both top-level helpers and grouped namespaces. This list is validated against the actual exports in src/index.ts.
Top-level exports
getOAuthTokendownloadWorkZoneCSVgenerateAllOnHandInventoryOfAllResourcesgenerateAllOnHandInventoryOfAllResourcesCSVdownloadAllResourcesCSVAllResourcesgetResourcebyIdgetworkSkillsOfResourceupdateResourcebyIddownloadAllUsersdownloadAllUsersCSVdownloadAllInactiveUsersCSVdownloadAllInactiveUsersgenerateUsersCollaborationCSVgetUserByLoginupdateUserbyLogindownloadAllInventoryTypesCSVgetInventoryTypesDetailupdateCreateInventoryTypegetAllActivitiesgetAllScheduledActivitiesgetAllNonScheduledActivitiesgetActivitybyIdstartActivitycancelActivitycompleteActivitydeleteActivitygetActivityCustomerInventoriescreateActivityCustomerInventoriesdownloadAllEventsOfDaydownloadAllEventsOfDayCSVdownloadAllEventsOfDLastTwoMinutesdownloadAllEventsOfLastOneHourcreateExcelFilecreateConfigurationFile
Grouped exports
The module-level namespace exports are:
ofs.ActivitygetAllActivitiesgetAllScheduledActivitiesgetAllNonScheduledActivitiesgetActivitybyIdstartActivitycancelActivitycompleteActivitydeleteActivity
ofs.ActivityInventoriesgetActivityCustomerInventoriescreateActivityCustomerInventories
ofs.EventsdownloadAllEventsOfDaydownloadAllEventsOfDayCSVdownloadAllEventsOfDLastTwoMinutesdownloadAllEventsOfLastOneHour
ofs.InventorygenerateAllOnHandInventoryOfAllResourcesgenerateAllOnHandInventoryOfAllResourcesCSV
ofs.InventoryTypedownloadAllInventoryTypesCSVgetInventoryTypesDetailupdateCreateInventoryType
ofs.CreateConfigurationFilecreateConfigurationFile
ofs.OauthTokenServicegetOAuthToken
ofs.ResourceAllResourcesdownloadAllResourcesCSVgetResourcebyIdgetworkSkillsOfResourceupdateResourcebyId
ofs.UserdownloadAllUsersdownloadAllUsersCSVdownloadAllInactiveUsersCSVdownloadAllInactiveUsersgenerateUsersCollaborationCSVgetUserByLoginupdateUserbyLogin
ofs.UtilitiescreateExcelFile
ofs.WorkZonedownloadWorkZoneCSV
Complete Example
This example shows a full CommonJS script that retrieves activity type metadata and prints the result.
const ofs = require("ofsc-utility");
async function main() {
const clientId = process.env.CLIENT_ID;
const clientSecret = process.env.CLIENT_SECRET;
const instanceUrl = process.env.INSTANCE_NAME;
if (!clientId || !clientSecret || !instanceUrl) {
throw new Error(
"Please set CLIENT_ID, CLIENT_SECRET and INSTANCE_NAME environment variables",
);
}
const activityTypes = await ofs.metadata.getActivityTypesMetaData(
clientId,
clientSecret,
instanceUrl,
);
console.log("Activity type metadata:");
console.log(JSON.stringify(activityTypes, null, 2));
}
main().catch((error) => {
console.error("Error running example:", error);
process.exit(1);
});Usage
Authentication
const token = await ofs.getOAuthToken(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);Download CSV files
await ofs.downloadWorkZoneCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
await ofs.downloadAllResourcesCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
await ofs.downloadAllUsersCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
await ofs.downloadAllInactiveUsersCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
14,
);Resource APIs
The resource helpers let you export, paginate, inspect, and update OFSC resources.
downloadAllResourcesCSV
Exports every resource in the OFSC resource collection to a local ./resources.csv file.
await ofs.downloadAllResourcesCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);What it does:
- Calls the OFSC
/resourcesendpoint in pages of 100 records. - Aggregates all returned items across all pages.
- Builds a union of all field names from the API payloads.
- Excludes nested relationship fields such as
links,inventories,users,workZones,workSkills, andworkSchedulesfrom the header set. - Writes the result to
./resources.csvin the current working directory. - Serializes arrays under the
keysfield as pipe-delimited strings and JSON-serializes object values for CSV compatibility.
Signature:
downloadAllResourcesCSV(
clientId: string,
clientSecret: string,
instanceUrl: string,
): Promise<void>AllResources
Fetches all resources across all pages and returns them as a single flattened array.
const resources = await ofs.AllResources(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(`Found ${resources.length} resources`);This helper is useful when you need to iterate through every resource object in memory, for analytics, reporting, or bulk transformations.
Signature:
AllResources(
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
): Promise<ResourceResponse[]>Notes:
- It paginates automatically until all results are fetched.
- It returns the flattened
itemscollection from every page rather than the raw API wrapper object. - The optional
initialTokenparameter can be supplied if you already have a valid bearer token available and want to reuse it.
getworkSkillsOfResource
Retrieves all work skills assigned to a specific resource.
const result = await ofs.getworkSkillsOfResource(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
12345,
);
console.log(result.data);
console.log(result.token);Signature:
getworkSkillsOfResource(
clientId: string,
clientSecret: string,
instanceUrl: string,
resourceId: number,
token?: string,
): Promise<{ token: string; data: any }>Return shape:
{
token: string,
data: any
}The data value is the items array returned by OFSC for the resource's work skills.
getResourcebyId
Fetches a single resource by its ID.
const resource = await ofs.getResourcebyId(
"resource-123",
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(resource);Signature:
getResourcebyId(
resourceId: string,
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
): Promise<ResourceResponse>The response is the raw OFSC resource payload returned by the API, so you can inspect its items, totalResults, and related metadata with the same structure returned by OFSC.
updateResourcebyId
Updates a resource record by ID using a PATCH request.
const payload = {
name: "Updated Resource Name",
status: "ACTIVE",
};
const response = await ofs.updateResourcebyId(
"resource-123",
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"",
payload,
);
console.log(response);Signature:
updateResourcebyId(
resourceId: string,
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
payload: object,
): Promise<ResourceResponse>Notes:
- The payload is sent as a PATCH body to the OFSC resource update endpoint.
- It uses the same retry-wrapper logic as the other OFSC API methods so transient gateway and 5xx failures are retried automatically.
- The returned value is the API response payload from OFSC.
Example: working with a resource and its work skills
const resourceId = "resource-123";
const resource = await ofs.getResourcebyId(
resourceId,
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
const workSkills = await ofs.getworkSkillsOfResource(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
Number(resourceId),
);
console.log("Resource:", resource);
console.log("Work skills:", workSkills.data);Download all users
downloadAllUsers retrieves every user from the OFSC Users API and returns the
results as an array of plain objects. The method automatically follows the API
pagination and does not create a CSV file.
const ofs = require("ofsc-utility");
async function downloadUsers() {
const users = await ofs.downloadAllUsers(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_URL,
);
console.log(`Downloaded ${users.length} users.`);
console.log(users[0]);
}
downloadUsers().catch((error) => {
console.error("Failed to download users:", error);
process.exit(1);
});Or, use the grouped namespace:
const users = await ofs.User.downloadAllUsers(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_URL,
);Function signature
downloadAllUsers(
clientId: string,
clientSecret: string,
instanceUrl: string,
): Promise<any[]>Parameters and result
clientId: OFSC OAuth client ID.clientSecret: OFSC OAuth client secret.instanceUrl: OFSC instance name only, such asmycompany. Do not includehttps://or.fs.ocs.oraclecloud.com.- The returned array contains every user returned by the API pages. Each user is represented as a plain object.
The helper retrieves users in pages of 100 records and requires valid OFSC API credentials. It obtains an OAuth token for each page and returns the combined results after the final page is reached.
To run the repository test script against a built distribution:
npm run build
export CLIENT_ID=yourClientId
export CLIENT_SECRET=yourClientSecret
export INSTANCE_URL=yourInstanceName
node scripts/test-download-all-users.jsDownload inactive users
downloadAllInactiveUsersCSV downloads all users from the OFSC Users API, filters
the results, and writes the matching users to ./inactive_users.csv.
A user is considered inactive when either:
lastLoginTimeis missing or cannot be parsed, or- the time since
lastLoginTimeis greater thaninactivityThresholdDays
The threshold defaults to 14 days. The comparison uses the current date and
time when the function runs. A user whose last login is exactly at the threshold
is not included because the function uses a strictly greater-than comparison.
const ofs = require("ofsc-utility");
async function downloadInactiveUsers() {
const clientId = process.env.CLIENT_ID;
const clientSecret = process.env.CLIENT_SECRET;
const instanceUrl = process.env.INSTANCE_NAME;
if (!clientId || !clientSecret || !instanceUrl) {
throw new Error(
"Set CLIENT_ID, CLIENT_SECRET and INSTANCE_NAME before running this example",
);
}
await ofs.downloadAllInactiveUsersCSV(
clientId,
clientSecret,
instanceUrl,
14,
);
}
downloadInactiveUsers().catch((error) => {
console.error("Failed to download inactive users:", error);
process.exit(1);
});Function signature
downloadAllInactiveUsersCSV(
clientId: string,
clientSecret: string,
instanceUrl: string,
inactivityThresholdDays?: number,
): Promise<void>Parameters
clientId: OFSC OAuth client ID.clientSecret: OFSC OAuth client secret.instanceUrl: OFSC instance name only, such asmycompany. Do not includehttps://or.fs.ocs.oraclecloud.com.inactivityThresholdDays: optional non-negative number of days. Defaults to14.
Output
- File:
./inactive_users.csv, relative to the process working directory. - The CSV contains one row per inactive user.
- Nested fields such as
resources,collaborationGroups,resourceInternalIds, andlinksare excluded. - The remaining columns are generated dynamically from the fields returned by
the API.
keysarrays are joined with|; other objects are serialized as JSON strings.
The helper retrieves users in pages of 100 records and requires valid OFSC API
credentials. It does not return the CSV contents; successful completion resolves
to void.
To run the repository test script against a built distribution:
npm run build
export CLIENT_ID=yourClientId
export CLIENT_SECRET=yourClientSecret
export INSTANCE_URL=yourInstanceName
export INACTIVITY_THRESHOLD_DAYS=14
node scripts/test-download-inactive-users.jsINACTIVITY_THRESHOLD_DAYS is optional in the test script and defaults to 14.
Collect inactive users
downloadAllInactiveUsers downloads users from the OFSC Users API, filters out
users whose last login is within the inactivity threshold, and returns the
matching users as an array of plain objects. It does not create a CSV file.
Unlike downloadAllInactiveUsersCSV, users with a blank or unparsable
lastLoginTime are skipped. The threshold defaults to 14 days, and a user is
included only when the time since the last login is strictly greater than the
threshold.
const ofs = require("ofsc-utility");
async function collectInactiveUsers() {
const users = await ofs.User.downloadAllInactiveUsers(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
14,
);
console.log(`Collected ${users.length} inactive users`);
console.log(users[0]);
}
collectInactiveUsers().catch((error) => {
console.error("Failed to collect inactive users:", error);
process.exit(1);
});Function signature
downloadAllInactiveUsers(
clientId: string,
clientSecret: string,
instanceUrl: string,
inactivityThresholdDays?: number,
): Promise<Record<string, any>[]>Parameters and result
clientId: OFSC OAuth client ID.clientSecret: OFSC OAuth client secret.instanceUrl: OFSC instance name only, such asmycompany. Do not includehttps://or.fs.ocs.oraclecloud.com.inactivityThresholdDays: optional non-negative number of days. Defaults to14.- The returned array contains one object per inactive user.
- Nested fields such as
resources,collaborationGroups,resourceInternalIds, andlinksare excluded. keysarrays are joined with|; other object values remain objects.
The helper retrieves users in pages of 100 records and requires valid OFSC API credentials.
To run the repository test script against a built distribution:
npm run build
export CLIENT_ID=yourClientId
export CLIENT_SECRET=yourClientSecret
export INSTANCE_URL=yourInstanceName
export INACTIVITY_THRESHOLD_DAYS=14
node scripts/test-download-inactive-users-data.jsINACTIVITY_THRESHOLD_DAYS is optional in the test script and defaults to 14.
Get user by login
getUserByLogin fetches a single user record by login name and returns the raw OFSC response payload.
const user = await ofs.getUserByLogin(
"[email protected]",
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(user);Function signature
getUserByLogin(
login: string,
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
): Promise<any>Notes:
- This method is intended for standalone OFSC environments.
- The response is the raw OFSC user payload returned by the API.
initialTokenis optional and can be reused if a bearer token is already available.
Update user by login
updateUserbyLogin updates a user record by login using a PATCH request.
const payload = {
firstName: "Updated",
lastName: "User",
status: "ACTIVE",
};
const response = await ofs.updateUserbyLogin(
"[email protected]",
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"",
payload,
);
console.log(response);Function signature
updateUserbyLogin(
login: string,
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
payload: object,
): Promise<ResourceResponse>Notes:
- The payload is sent as a PATCH body to the OFSC user update endpoint.
- It uses the same retry wrapper as the other OFSC API helpers.
- This method is also intended for standalone OFSC usage and may not behave the same in Fusion OFSC.
Resource related methods
Note: User and resource-related methods are applicable exclusively to standalone OFSC environments and are not supported in Fusion OFSC.
These methods are for standalone OFSC environments only. If you are connecting to Fusion OFSC, the user- and resource-based APIs may not behave the same way, and the request/response structure may not match the standalone endpoints.
Get all resources
AllResources retrieves all resources from the OFSC Resources API. Results are
fetched in pages of 100 records until every resource has been returned.
const resources = await ofs.AllResources(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(`Loaded ${resources.length} resources`);Function signature
AllResources(
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
): Promise<ResourceResponse[]>initialToken is optional. The helper refreshes the token as needed while
requesting subsequent pages.
Get a resource by ID
getResourcebyId fetches a single resource by its resource ID and returns the
OFSC response envelope.
const resource = await ofs.getResourcebyId(
"5457",
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(resource.items);Function signature
getResourcebyId(
resourceId: string,
clientId: string,
clientSecret: string,
instanceUrl: string,
initialToken?: string,
): Promise<ResourceResponse>The returned response contains items, offset, limit, and totalResults.
initialToken is optional.
Get resource work skills
getworkSkillsOfResource retrieves the work skills assigned to a resource.
The result includes the token returned by the request and the skills in data.
const workSkills = await ofs.getworkSkillsOfResource(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
5457,
);
console.log(workSkills.data);Function signature
getworkSkillsOfResource(
clientId: string,
clientSecret: string,
instanceUrl: string,
resourceId: number,
token?: string,
): Promise<{ token: string; data: any }>token is optional. data contains the work-skill items returned by OFSC.
await ofs.generateAllOnHandInventoryOfAllResourcesCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);This helper fetches all active resources and writes their on-hand inventory rows to a CSV file.
const inventoryResult = await ofs.generateAllOnHandInventoryOfAllResources(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(`Loaded ${inventoryResult.data.length} inventory rows`);
console.log("Available table columns:", inventoryResult.props);This method fetches active resources and returns an object containing:
data: an array of inventory row objectsprops: an array of unique keys found across all row objects
The props array can be used as your dynamic table columns. For example:
const columns = inventoryResult.props;
const rows = inventoryResult.data;
columns.forEach((col) => {
console.log(`Column: ${col}`);
});
rows.forEach((row) => {
const cells = columns.map((col) => row[col]);
console.log(cells);
});This gives you a dynamic table definition based on the actual inventory row fields returned by OFSC.
Activity and inventory helpers
The activity API supports both listing and lifecycle actions. Prefer the grouped namespace for organization:
const activities = await ofs.Activity.getAllActivities(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"US",
"2025-11-01",
"2025-11-30",
"status=='pending'",
"activityId,activityType,date,status",
true,
);
const activityData = await ofs.Activity.getActivitybyId(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
const scheduledActivities = await ofs.Activity.getAllScheduledActivities(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"US",
);
const nonScheduledActivities = await ofs.Activity.getAllNonScheduledActivities(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"US",
"activityId,activityType,status",
);
console.log("Scheduled activities:", scheduledActivities.length);
console.log("Non-scheduled activities:", nonScheduledActivities.length);
await ofs.Activity.startActivity(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
await ofs.Activity.completeActivity(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
await ofs.Activity.cancelActivity(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
await ofs.Activity.deleteActivity(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
const customerInventories = await ofs.ActivityInventories.getActivityCustomerInventories(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
const createdInventory = await ofs.ActivityInventories.createActivityCustomerInventories(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
{
code: "INV-1001",
quantity: 1,
status: "active",
},
);
const inventoryDetail = await ofs.InventoryType.getInventoryTypesDetail(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"inventory_label",
);Activity lifecycle actions
The activity helper set lets you query scheduled and non-scheduled activity work, then transition an OFSC activity through its standard lifecycle actions:
getAllScheduledActivities(clientId, clientSecret, instanceUrl, rootBucket)getAllNonScheduledActivities(clientId, clientSecret, instanceUrl, resources, fields?)startActivity(clientId, clientSecret, instanceUrl, activityId)completeActivity(clientId, clientSecret, instanceUrl, activityId)cancelActivity(clientId, clientSecret, instanceUrl, activityId)deleteActivity(clientId, clientSecret, instanceUrl, activityId)
Example:
let rootBucket = "US";
const scheduled = await ofs.Activity.getAllScheduledActivities(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
rootBucket,
);
console.log("Scheduled activities:", scheduled.length);Example:
let rootBucket = "US";
const nonScheduled = await ofs.Activity.getAllNonScheduledActivities(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
rootBucket,
"activityId,activityType,date,status",
);
console.log(nonScheduled.length);Example:
const started = await ofs.Activity.startActivity(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
console.log(started.data);Create a configuration workbook
await ofs.createConfigurationFile(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"OFSC_CONFIGURATION_SHEET.xlsx",
);The workbook includes a Subscription Config sheet with subscription IDs,
serialized subscription configurations, and application IDs.
Metadata helpers
The metadata group exposes metadata-specific retrieval helpers.
const meta = ofs.metadata;
const activityTypes = await meta.getActivityTypesMetaData(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
const activityGroups = await meta.getActivityTypesGroupsMetaData(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
const workZones = await meta.getWorkZonesMetaData(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);Namespace-style imports
const ofs = require("ofsc-utility");
await ofs.WorkZone.downloadWorkZoneCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
await ofs.User.generateUsersCollaborationCSV(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
process.env.SUBSCRIPTION_ID,
);Default export object
The default export object exposes the same functions in a single object, with the metadata helpers grouped under metadata:
const ofs = require("ofsc-utility");
const activities = await ofs.Activity.getAllActivities(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"US",
"2025-11-01",
"2025-11-30",
);
await ofs.Activity.startActivity(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
123456,
);
const meta = ofs.metadata;
const activityTypes = await meta.getActivityTypesMetaData(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);Metadata namespace
The metadata object exposes metadata helpers such as:
getActivityTypesMetaDatagetActivityTypesGroupsMetaDatagetApplictaionsIntegrationsDetailMetaDatagetCapacityMetaDatagetFormsMetaDatagetInventoryTypesMetaDatagetSubscriptionsMetaDatagetPropertiesMetaDatagetPropertyMetaDataupdatePropertyEnumgetResourceTypesMetaDatagetShiftMetaDatagetTimeSlotsMetaDatagetWorkSkillsMetaDatagetWorkZoneKeyMetaDatagetWorkZonesMetaDatacreateConfigurationFile
Subscription metadata
Use getSubscriptionsMetaData to retrieve the instance's event subscriptions.
It returns an object with a Subscription Config array. Each row contains
subscriptionId, subscriptionConfig (serialized as JSON), and applicationId.
The optional fourth argument is an existing OAuth token; omit it or pass an
empty string to let the request helper obtain a token.
const subscriptions = await ofs.metadata.getSubscriptionsMetaData(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
process.env.TOKEN || "",
);
console.log(subscriptions["Subscription Config"]);To try the method from the repository, build the package, load credentials from
scripts/.env, and run the test script:
npm run build
source scripts/.env
node scripts/test-get-subscriptions-meta-data.jsSet OUTPUT_FILE_NAME to save the returned object as JSON.
Properties metadata note
The getPropertiesMetaData helper fetches OFSC property definitions and then builds:
Properties Overview: one row per property, including label, name, type, entity, GUI, clone flag, and deduplicated commentsProperties Enumerations: combined enumeration dropdown values for any properties whose data type isenumeration
This function requires an allUsedPropes array to identify which properties are referenced by other metadata types and to collect comments for the overview.
const allPropes = [];
const propertiesSheet = await ofs.metadata.getPropertiesMetaData(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
allPropes,
);
console.log(propertiesSheet["Properties Overview"]);
console.log(propertiesSheet["Properties Enumerations"]);Single property metadata note
The getPropertyMetaData helper fetches metadata for one property label. It requests that property directly from the OFSC metadata API rather than fetching the full property catalog.
This function accepts:
propertyLabel: the property label to fetch, such aswork_zoneormanagerclientId: OFSC client IDclientSecret: OFSC client secretinstanceUrl: OFSC instance name only, for examplemycompanytoken: optional existing OAuth token; omit it or pass an empty string to let the request helper obtain a token
The returned promise resolves to an object with:
data: the raw metadata object for the requested property returned by the OFSC APIenums: the raw enumeration-list array for that property when its data type isenumeration; otherwise an empty array
const propertyMetadata = await ofs.metadata.getPropertyMetaData(
"work_zone",
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
);
console.log(propertyMetadata.data);
console.log(propertyMetadata.enums);Example return value (the property and enumeration fields depend on the OFSC instance):
{
"data": {
"label": "work_zone",
"name": "workZone",
"type": "enumeration",
"entity": "resource",
"gui": "dropdown"
},
"enums": [
{
"label": "HOME",
"active": true,
"translations": [
{
"language": "en",
"name": "Home office"
}
]
}
]
}The example is illustrative; the exact fields in data and each item in enums are determined by the API response. For a non-enumeration property, enums is []. An empty or whitespace-only propertyLabel throws an error.
Updating property enumeration values
Use updatePropertyEnum to send an enumeration-list update for a property through the OFSC metadata API. It requires the property label and a payload containing an items array. Each item must include a string label, boolean active, and a translations array. Each translation must include string language, name, and languageISO fields. Multiple items and multiple translations per item are supported.
const response = await ofs.metadata.updatePropertyEnum(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.INSTANCE_NAME,
"custom_status",
{
items: [
{
label: "DATABASE_CONNECTION_ERROR",
active: true,
translations: [
{
language: "en",
name: "Database Connection Error",
languageISO: "en-US",
},
{
language: "fr",
name: "Erreur de connexion à la base de données",
languageISO: "fr-FR",
},
],
},
{
label: "SERVICE_UNAVAILABLE",
active: true,
translations: [
{
language: "en",
name: "Service Unavailable",
languageISO: "en-US",
},
],
},
],
},
process.env.TOKEN || "",
);
console.log(response);The optional token follows the payload argument. Invalid payload shapes or field types throw an error before the API request is made.
The repository includes scripts/test-update-property-enum.js for trying this helper with a JSON payload file. After building with npm run build, set CLIENT_ID, CLIENT_SECRET, INSTANCE_URL, PROPERTY_LABEL, and ENUM_PAYLOAD_PATH, then run:
node scripts/test-update-property-enum.jsThe script prints a dry-run preview by default. Set APPLY_ENUM_UPDATE=true to send the update.
Notes
instanceUrlis the OFSC instance name only, not the full URL. For example:mycompanyformycompany.fs.ocs.oraclecloud.com.- All API helper methods accept the same
clientId,clientSecret, andinstanceUrlparameters at minimum. - Most helper methods return a promise and should be used with
awaitor.then().
Testing
npm testLicense
MIT
