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.

Installing with yum

If you're using Oracle Linux 7 or 8, you can use yum to install the OCI SDK for TypeScript and JavaScript.

For Oracle Linux 8:

sudo yum module enable nodejs:14
sudo yum install oci-typescript-sdk

For Oracle Linux 7:

sudo yum install oracle-nodejs-release-el7
sudo yum install --enablerepo=ol7_developer_nodejs14 --enablerepo=ol7_developer oci-typescript-sdk

The oci-typescript-sdk yum package will only work for Node version 10.X.X. The oci-sdk package will be installed into the global node_modules folder. To use the oci-sdk package in a project, link the oci-sdk global package to your local project.

For example:
# Assuming you are in your project's top level directory
npm link oci-sdk
# You should now see oci-sdk package in your local project's node_modules folder

Because the oci-sdk package is globally installed, you must update the import statements for oci-sdk's sub-packages when running the oci-typescript-sdk examples on GitHub.

For example:
import * as identity from "oci-identity"; // Change needed
import * as oci from "oci-sdk"; // No change needed
import * as identity from "oci-sdk/node_modules/oci-identity"; //Changed
import * as oci from "oci-sdk"; // No change

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") || "";