Getting Started

This topic describes how to install and configure the SDK for TypeScript and JavaScript.

To use the Oracle Cloud Infrastructure SDK for TypeScript and JavaScript in your project, import any service from ./oci-typescript-sdk/index.ts. For example:

// Container Engine

export import containerengine = require("oci-containerengine");

// Core

export import core = require("oci-core");

// Database

export import database = require("oci-database");

Downloading the SDK from GitHub

You can download the SDK for TypeScript and JavaScript as a zip archive from GitHub. It contains the SDK, all of its dependencies, documentation, and examples.

Using the SDK for TypeScript and JavaScript with NPM

NPM.

Configuring the SDK

The SDK services need two types of configuration: credentials and client-side HTTP settings.

Configuring Credentials

First, you need to set up your credentials and config file. For instructions, see SDK and CLI Configuration File.

The default configuration location is "~/.oci/config" and "DEFAULT" profile is used. You can use ConfigFileAuthenticationDetailsProvider with or without specifying the configuration location and profile name:

// TypeScript
import common = require("oci-common");
// Using default configuration
const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider();
// Using personal configuration
const configurationFilePath = "~/your_config_location";
const configProfile = "your_profile_name";
const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider(
  configurationFilePath,
  configProfile
);
// JavaScript
const common = require("oci-common");
// Using default configurations
const provider = new common.ConfigFileAuthenticationDetailsProvider();
// Using personal configuration
const configurationFilePath = "~/your_config_location";
const configProfile = "your_profile_name";
const provider = new common.ConfigFileAuthenticationDetailsProvider(
  configurationFilePath,
  configProfile
);

Configuring Custom Options

In the configuration file, you can insert custom key-value pairs that you define, and then reference them as necessary. For example, you could specify a frequently used compartment ID in the config file:

[DEFAULT]
user=ocid1.user.oc1..<your_unique_id>
fingerprint=<your_fingerprint>
key_file=~/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..<your_unique_id>
customCompartmentId=ocid1.compartment.oc1..<your_unique_id>

Then you can retrieve the value:

// TypeScript
import common = require("oci-common");
const configurationFilePath = "~/your_config_location";
const configProfile = "your_profile_name";
const config = common.ConfigFileReader.parseDefault(configurationFilePath);
const profile = config.accumulator.configurationsByProfile.get(configProfile);
customCompartmentId = profile.get("customCompartmentId") || "";

// JavaScript
import common = require("oci-common");
const configurationFilePath = "~/your_config_location";
const configProfile = "your_profile_name";
const config = common.ConfigFileReader.parseDefault(configurationFilePath);
const profile = config.accumulator.configurationsByProfile.get(configProfile);
customCompartmentId = profile.get("customCompartmentId") || "";