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.
Copy
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:
Copy
import {AdminClient} from "@truststack/admin";const client = new AdminClient();const organizations = await client.createOrganization({name: "ACME Farms"});
You can configure the SDK globally and set your access token.
Copy
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.
Copy
import {CanvasClient} from "@truststack/canvas";// Access token is automatically used from aboveconst 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.
Copy
import {CanvasClient} from "@truststack/canvas";import {AdminClient} from "@truststack/admin";import {TrustStackClient} from "@truststack/core";CanvasClient.configure({accessToken: "<access_token>"});// orAdminClient.configure({accessToken: "<access_token>"});// orTrustStackClient.configure({accessToken: "<access_token>"});
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:
You can also set the organization on a per request basis. Most module functions accept a second set of parameters to do this.
Copy
import {CanvasClient} from "@truststack/canvas";const client = new CanvasClient();await client.createCanvasTemplate( {name: "My Canvas"}, {organization: "<organization_id>"});
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.