Installation

To get started, install the Trust Stack SDK.

npm install @truststack/sdk

Modules

The Trust Stack SDK is also available as a set of NPM packages to keep your codebase clean and focused. Read more about modules to learn more.

Each core functionality is either available per the TrustStack client in @truststack/sdk or as a module in the @truststack/<MODULE> package.

import {TrustStack} from "@truststack/sdk";

const truststack = new TrustStack();
const organizations = await truststack.admin.createOrganization({
  name: "ACME Farms",
});

Or, alternatively, via only installing the @truststack/admin:

import {AdminClient} from "@truststack/admin";

const client = new AdminClient();
const organizations = await client.createOrganization({name: "ACME Farms"});

Access Token Configuration

You can configure the SDK globally and set your access token.

import {TrustStack} from "@truststack/sdk";

const truststack = TrustStack.configure({accessToken: "<access_token>"});

Subsequent module usage will use the access token you have configured. Below is an example of how to use the Canvas module.

import {CanvasClient} from "@truststack/canvas";

// Access token is automatically used from above
const client = new CanvasClient();
await client.createCanvasTemplate({name: "My Canvas"});

You can also configure globally with each module as well. The following examples all have the same effect.

import {CanvasClient} from "@truststack/canvas";
import {AdminClient} from "@truststack/admin";
import {TrustStackClient} from "@truststack/core";

CanvasClient.configure({accessToken: "<access_token>"});
// or
AdminClient.configure({accessToken: "<access_token>"});
// or
TrustStackClient.configure({accessToken: "<access_token>"});

Environment Variables

You can also set the access token via environment variables.

TRUSTSTACK_ACCESS_TOKEN=<access_token>

Organization Configuration

It is recommended you read about Organizations before continuing.

Most actions within the Trust Stack require the concept of a “Organization”. The Organizations section has more information but setting the organization is important to ensure your requests are made in the correct context.

It enforces permissions and authorization for the actions you perform on hehalf of your user groups.

There are a few ways to set the organization.

You can set the organization globally:

Globally Set Organization

import {TrustStack} from "@truststack/core";

const truststack = TrustStack.configure({
  organization: "<organization_id>",
  accessToken: "<access_token>",
});

Per client set organization

You can also set the organization on a per client basis.

import {CanvasClient} from "@truststack/canvas";

const client = new CanvasClient({organization: "<organization_id>"});

Per request set organization

You can also set the organization on a per request basis. Most module functions accept a second set of parameters to do this.

import {CanvasClient} from "@truststack/canvas";

const client = new CanvasClient();
await client.createCanvasTemplate(
  {name: "My Canvas"},
  {organization: "<organization_id>"}
);

No organization?

If you don’t set an organization, the SDK will default your tenant as the organization. If you are require DIDs, Credentials, or other resources, you will need to set the organization. managed against your tenant, this is the default behavior.