OCI NodeJS Client for Distributed Database Service
The `oci-distributeddatabase` package provides the TypeScript and JavaScript client for managing resources within Oracle Cloud Infrastructure's (OCI) Distributed Database Service. This service is designed for deploying and managing Globally Distributed Databases and Globally Distributed Autonomous Databases, which offer linearly scalable, multi-model database solutions ensuring high availability, low latency, and adherence to data sovereignty requirements. The current stable version is 2.130.0, with Oracle maintaining a frequent release cadence, often aligning security updates with their Critical Patch Update program. As part of the broader OCI SDK, it leverages a consistent authentication and configuration model across all OCI services. It's built for Node.js environments (supporting versions 14, 16, 18, 20) and ships with TypeScript type definitions, but it does not support browser environments.
Common errors
-
Error: did not find a proper configuration for user
cause The SDK could not locate or parse the OCI configuration file, or the specified profile is missing/invalid.fixVerify that `~/.oci/config` exists and is accessible, the `[DEFAULT]` profile or the specified profile is correctly configured, and the necessary environment variables (`OCI_CONFIG_FILE`, `OCI_PROFILE_NAME`) are set if not using the default location/profile. -
ServiceError: NotAuthorizedOrNotFound. Authorization failed or requested resource not found.
cause The OCI user/instance principal lacks the necessary IAM permissions to perform the requested operation or access the resource, or the resource genuinely does not exist.fixCheck OCI IAM policies for the user/group associated with the credentials. Ensure policies grant appropriate `manage` or `read` permissions for `globally-distributed-database-family` or specific resources within the target compartment. Double-check resource OCIDs and compartment IDs. -
ETIMEDOUT
cause A network timeout occurred, preventing the SDK from receiving a response from the OCI service within the configured timeout period.fixIncrease the client's timeout setting if appropriate, check network connectivity to OCI endpoints, verify region configuration, and ensure no firewalls or proxies are blocking traffic. -
TypeError: Cannot read properties of undefined (reading 'items')
cause Often occurs when an API response structure is unexpected, frequently due to an empty or malformed response object from the OCI service, or incorrect access of response properties.fixAdd robust checks for `null` or `undefined` on API response objects and their properties. Ensure the service operation was successful before attempting to access nested data. This can sometimes indicate an underlying authorization issue (see `NotAuthorizedOrNotFound`).
Warnings
- breaking The OCI TypeScript/JavaScript SDK frequently introduces breaking changes in minor versions, often involving removal or renaming of fields and models within specific service client packages. Always consult the CHANGELOG.md for the specific version before upgrading.
- gotcha The SDK for TypeScript/JavaScript has a known issue with potential data rounding for numbers exceeding JavaScript's `Number.MAX_SAFE_INTEGER`. This can affect large integer values returned by OCI services.
- gotcha The OCI TypeScript/JavaScript SDK is designed exclusively for Node.js environments and does not support running in web browsers. Attempts to use it in a browser context will result in runtime errors.
- gotcha Incorrect OCI IAM policies or misconfigured credentials (e.g., missing `~/.oci/config` file, invalid profile, incorrect key pair) are common causes of errors, often manifesting as 'Not Authorized' or 'Not Found' (due to lack of permission to even see the resource).
- gotcha Using unsupported Node.js or TypeScript versions can lead to unexpected behavior or compilation issues. The SDK currently supports Node.js 14, 16, 18, 20 and TypeScript 4.1.3.
Install
-
npm install oci-distributeddatabase -
yarn add oci-distributeddatabase -
pnpm add oci-distributeddatabase
Imports
- DistributedDatabaseClient
const DistributedDatabaseClient = require('oci-distributeddatabase').DistributedDatabaseClient;import { DistributedDatabaseClient } from 'oci-distributeddatabase'; - models
import { models } from 'oci-distributeddatabase';import * as models from 'oci-distributeddatabase/lib/model';
- ConfigFileAuthenticationDetailsProvider
import { ConfigFileAuthenticationDetailsProvider } from 'oci-distributeddatabase';import { ConfigFileAuthenticationDetailsProvider } from 'oci-common';
Quickstart
import { DistributedDatabaseClient } from 'oci-distributeddatabase';
import { ConfigFileAuthenticationDetailsProvider } from 'oci-common';
import * as models from 'oci-distributeddatabase/lib/model';
// Ensure OCI configuration is set up at ~/.oci/config or via environment variables.
// For programmatic configuration, ensure OCI_CONFIG_FILE and OCI_PROFILE_NAME are set,
// or provide explicit paths.
// For example:
// process.env.OCI_CONFIG_FILE = '~/.oci/config';
// process.env.OCI_PROFILE_NAME = 'DEFAULT';
const compartmentId = process.env.OCI_COMPARTMENT_ID ?? '';
async function listDistributedAutonomousDatabases() {
if (!compartmentId) {
console.error('Error: OCI_COMPARTMENT_ID environment variable is not set.');
process.exit(1);
}
try {
const provider = new ConfigFileAuthenticationDetailsProvider();
const client = new DistributedDatabaseClient({ authenticationDetailsProvider: provider });
console.log(`Listing Distributed Autonomous Databases in compartment: ${compartmentId}...`);
const listRequest: models.ListDistributedAutonomousDatabasesRequest = {
compartmentId: compartmentId,
limit: 10 // Limiting results for brevity
};
const response = await client.listDistributedAutonomousDatabases(listRequest);
if (response.distributedAutonomousDatabaseCollection.items.length > 0) {
console.log('Found Distributed Autonomous Databases:');
for (const db of response.distributedAutonomousDatabaseCollection.items) {
console.log(`- ${db.displayName} (OCID: ${db.id}) - Lifecycle State: ${db.lifecycleState}`);
}
} else {
console.log('No Distributed Autonomous Databases found in the specified compartment.');
}
} catch (error) {
console.error('Failed to list Distributed Autonomous Databases:', error);
}
}
listDistributedAutonomousDatabases();