Add an Ontology SDK package to an existing application

This page will walk you through the process of adding an Ontology SDK package to an existing application. If you do not have an existing application, view the documentation on bootstrapping a new Ontology SDK application.

1: Prerequisites

Create a Developer Console application

Follow the steps listed in the create a new Developer Console application page.

Set up your token

Export your token in your local environment. Below is an example using a sample personal access token, but you can generate a longer-lived one in the Developer Console. This token should not be checked into source control because it is your personal access token.

Copied!
1 export FOUNDRY_TOKEN=<YOUR-TOKEN-FROM-GETTING-STARTED-PAGE>

Check Node version

The Typescript SDK requires Node 18 or higher to work. To check what version of Node you are on, use the command below.

Copied!
1 node --version

2: Add the Ontology SDK to an existing Project

Set up the NPM registry

Add the following code to your repository or user .npmrc file, replacing any < > with an application-specific value:

//<REGISTRY-URL-FROM-OVERVIEW-PAGE>:_authToken=${FOUNDRY_TOKEN}
<PACKAGE-NAME>:registry=https://<REGISTRY-URL-FROM-OVERVIEW-PAGE>

Optional: Set up certificate

If your organization requires certificates for network traffic, you may need to tell Node where that certificate lives.

Copied!
1 export NODE_EXTRA_CA_CERTS="/path/to/my.crt"

Install the latest version of the SDK

Run the following command to install your SDK package:

Copied!
1 npm install <PACKAGE-NAME>@latest

Initialize the Foundry client to start developing

Add the following code to your application, replacing any < > with the specifics of your package:

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 import { FoundryClient, PublicClientAuth } from "<PACKAGE-NAME>/sdk"; import { <ANY-OBJECT-NAME> } from "<PACKAGE-NAME>/sdk/ontology/objects"; import React, { useEffect } from "react"; export const client = new FoundryClient({ url: "<YOUR-FOUNDRY-URL>", auth: new PublicClientAuth({ clientId: "<YOUR-CLIENT-ID>", url: "<YOUR-FOUNDRY-URL>", redirectUrl: "<YOUR-REDIRECT-URL>", }), }); export default function SimpleReactComponent() { useEffect(() => { if (client.auth.token == null || client.auth.token.isExpired) { client.auth .refresh() .catch(() => { // If we cannot refresh the token (for example, if the user is not logged in) we initiate the login flow in Foundry // Once login is complete, the user will be redirected back to http://localhost:8080/auth/callback client.auth.signIn(); }); } else { client.ontology.objects.<YOUR-OBJECT-NAME> .all() .then(objects => { console.log(objects); }); } }, []); };