Link SDK
@truto/truto-link-sdk is a browser SDK for connecting your customer's accounts to Truto. It opens the Connect UI, where your customer connects an account, and RapidForm for post-connection data selection.
Try it live: The Truto Link SDK Playground lets you try Connect, File Picker, and RapidForm flows interactively — no setup required.
Installation
npm install @truto/truto-link-sdkTruto Connect
To show the Connect UI, generate a link-token via the Truto API from your backend server. See Create Link Token.
import authenticate from '@truto/truto-link-sdk';
const linkToken = 'link-token-uuid';
authenticate(linkToken, {})
.then((response) => {
console.log(response);
// { result: 'success', integration: 'copper', integrated_account_id: '...', post_connect_form: '{}' }
})
.catch((error) => {
console.log(error);
});RapidForm
A token from POST /integrated-account/token is a backend credential. With it, GET /integrated-account/me returns the account's decrypted credentials, including OAuth refresh tokens and API keys. Don't pass it to a browser. authenticate already shows the RapidForm after a connection. To let end users change their selections later, turn on Reopen setup forms for the connections widget and use its Configure action.
To show the RapidForm, generate an integrated-account-token via the API. See Create Integrated Account Token.
import { rapidForm } from '@truto/truto-link-sdk';
const integratedAccountToken = 'integrated-account-token-uuid';
rapidForm(integratedAccountToken, {})
.then((response) => {
console.log(response);
// { result: 'success', integration: 'copper', integrated_account_id: '...', post_connect_form: '{}' }
})
.catch((error) => {
console.log(error);
});Options
Both authenticate and rapidForm accept these options as the second argument:
| Option | Type | Description |
|---|---|---|
integration |
string |
Pre-select an integration, skipping the selection screen |
iframe |
boolean |
Show the UI in a full-screen iframe overlay on your page (default: true). Set to false to open a popup window instead |
sameWindow |
boolean |
Navigate the current window to the Connect UI or RapidForm instead of opening an overlay or popup (default: false). The function then returns nothing, so there is no promise to await. With authenticate, the result arrives as query parameters on the link token's redirect_uri (see Return to your app with redirect_uri); with rapidForm, no result comes back to your page |
width |
number |
Popup window width in pixels when iframe is false (default: 700) |
height |
number |
Popup window height in pixels when iframe is false (default: 800) |
baseUrl |
string |
Origin serving the Connect UI and RapidForm, for self-hosted or staging deployments (default: https://app.truto.one). Must be an absolute http(s) URL |
authenticate also accepts:
| Option | Type | Description |
|---|---|---|
noBack |
boolean |
Hide the "Back" button on the Connect UI |
authFormat |
string |
Open the integration on one sign-in method: api_key, oauth2, oauth, oauth2_client_credentials, keka_oauth, jwt_bearer, or aws_sts. Ignored when the integration doesn't offer that method |
skipRapidForm |
boolean |
Skip the RapidForm UI after account connection |
integrations |
string[] |
Limit which integrations are shown. A one-item list still shows the integration list; use integration to skip it |
rapidForm also accepts:
| Option | Type | Description |
|---|---|---|
additionalContext |
object |
Stored under the context attribute of the integrated account |
preventDeselect |
object |
Prevent deselection of multi-select values in RapidForm |
disabledFields |
object |
Disable specific fields in RapidForm |
Return to your app with redirect_uri
A link token's redirect_uri (see Create Link Token) sends the end user to your URL when the connection flow ends, with the result in query parameters.
Leave redirect_uri off link tokens you pass to authenticate in overlay or popup mode. When the flow ends, the Connect UI goes to redirect_uri wherever it runs, inside the overlay or popup too, so the promise never settles. Use redirect_uri only with sameWindow: true or with a connection link you send to your customer.
| Result | Query parameters Truto adds |
|---|---|
| Success | result=success, integration, integrated_account_id |
| Failure | result=error, integration, error, error_type, and integrated_account_id only when an account exists |
- Query parameters already on your URL are kept. On a name clash, Truto's value wins.
post_connect_formis not passed.- The value must be an absolute URL. A custom scheme, such as
acme://connectedfor a desktop app, works. Truto doesn't validate the value when you create the link token: a value that isn't an absolute URL is ignored when the flow ends. - With
sameWindow: trueand noredirect_uri, the end user stays on Truto's "Connection successful" page. - An invalid or expired link token never redirects. Credentials refused on an API key form show their error on the form and don't redirect either.
Error Handling
Errors follow this structure:
{
"result": "error",
"error": "string describing the error",
"error_type": "invalid_token | invalid_integration | connection_error | app_credentials_not_configured | post_install_error | validation_error | rapid_form_error",
"integration": "integration name",
"integrated_account_id": "integrated account id, when one exists"
}integrated_account_id is present only when the failure concerns an account that already exists: a re-authorization that was refused or failed, and post_install_error or validation_error after the account was created. A first connection that fails before the account exists, such as the user cancelling on the provider's consent screen, carries no integrated_account_id key at all. The same applies to the query parameters appended to a link token's redirect_uri.
| Error Type | Description |
|---|---|
invalid_token |
The link token is invalid or expired |
invalid_integration |
Invalid or uninstalled integration name |
connection_error |
Error during the connection flow. When the provider refuses authorization, for example the user cancels on the consent screen, error carries the provider's own reason (error_description when the provider sends one, otherwise its error code, such as access_denied), truncated to 300 characters. |
app_credentials_not_configured |
The integration cannot be connected yet: its app credentials (your own OAuth app, or AWS STS signing credentials) are not configured in the environment. error carries the same string. In full-page mode the end user is shown who to contact; in iframe and popup modes the dialog closes, so show your own message. An admin fixes it under the integration's Configuration tab (see Overriding OAuth credentials). |
post_install_error |
Post-install steps failed after account creation |
validation_error |
Validation requests failed after account creation |
rapid_form_error |
Error opening or processing RapidForm |
When the user closes the overlay or popup without finishing, the promise rejects with the string "closed" instead of an object. When the browser blocks the popup (iframe: false), it rejects with the string "blocked". Any other rejection is a JavaScript Error whose message is error and that carries the fields above, plus is_truto: true, as properties. Check typeof error === 'string' first. The success object also has is_truto: true, and its post_connect_form is a JSON string.
"closed" means the user left the flow, not that nothing connected: a user who closes the RapidForm has already connected an account. Use the integrated_account:created and integrated_account:active webhooks on your backend as the source of truth.
Styling the Connect UI
authenticate takes no styling options. The Connect UI's brand name, icon, consent terms, and custom CSS are set per environment under Settings → Branding in the Truto dashboard and apply to every connection that environment opens. Custom CSS targets thirteen data-truto-el elements, such as card and submit; load the Connect UI with ?custom_css=off to see it without your stylesheet. See Brand the Connect UI.
Embedded widgets
widgets.connections() mounts Truto's connections widget inline, inside an element you own, instead of as an overlay. It lists the integrations enabled in your environment and one tenant's connections, with the actions the environment allows: Connect, Reconnect, Refresh, Delete, Configure and Add another. Your backend mints a session token for the tenant with POST /session-token, and the environment must list your page's origin under Settings → Connections widget → Allowed origins.
import { widgets } from '@truto/truto-link-sdk';
const widget = widgets.connections({
container: document.getElementById('integrations'),
environmentId: '<environment_id>',
getToken: async () => {
const response = await fetch('/api/truto/session-token', { method: 'POST' });
return response.json(); // { session_token, expires_at }
},
onEvent: (e) => console.log(e.event, e.payload),
});
// On unmount, route change, or sign-out.
widget.destroy();The widget has its own theme and custom CSS, separate from the Connect UI's. See Embed the connections widget for session tokens, every option and event, capabilities, and styling.
Native File Pickers
The pickers take a token from POST /integrated-account/token, which is a backend credential. With it, GET /integrated-account/me returns the account's decrypted credentials, including OAuth refresh tokens and API keys. Don't pass it to a browser.
Show vendor-native file picker UIs for cloud storage integrations. showFilePicker accepts sharepoint, onedrive, googledrive (or google), box, dropbox and dropboxpersonal as the integration name. The pickers always talk to https://api.truto.one and do not read baseUrl.
Each picker resolves with the picked items, after trutoExpression (see File Picker Transforms), and saves them on the integrated account as drive_items. Google Drive, Box and Dropbox reject with an Error whose message is User cancelled file selection when the user cancels. An unsupported integration name returns undefined instead of a promise. useGoogleFilePicker, useBoxFilePicker and useDropboxFilePicker are also exported, to open one picker directly.
SharePoint / OneDrive
import { showFilePicker } from '@truto/truto-link-sdk';
const integratedAccountToken = 'integrated-account-token-uuid';
showFilePicker('sharepoint', integratedAccountToken, {})
.then((response) => {
console.log(response);
});Google Drive
appId is your Google Cloud project number.
import { showFilePicker } from '@truto/truto-link-sdk';
showFilePicker('googledrive', integratedAccountToken, {
appId: '1234567890',
title: 'Choose Files',
maxItems: 5,
views: [
{ viewId: 'DOCS', includeFolders: true, selectFolderEnabled: true },
{ enableDrives: true, includeFolders: true },
],
}).then((response) => {
console.log(response);
});Box
The Box picker calls Box from your page, so Box must allow your site's origin. That needs your own Box app: install Box with your own OAuth app, then add your site's origin (for example https://app.example.com) under CORS Domains in that app's configuration. Truto's shared Box app can't list your domain.
showFilePicker('box', integratedAccountToken, {})
.then((response) => console.log(response));Dropbox
Add your site's domain to the Allowed Domains in your Dropbox Developer Console, on the Dropbox app whose key you pass as
appKey.
Use dropboxpersonal instead of dropbox for Dropbox personal accounts.
showFilePicker('dropbox', integratedAccountToken, {
appKey: 'your-dropbox-app-key',
}).then((response) => console.log(response));File Picker Transforms
Use trutoExpression (a JSONata expression) to transform picked items before they are stored:
showFilePicker('onedrive', integratedAccountToken, {
trutoExpression: "$.($merge([{'selected_at': $now()}, $]))",
}).then((response) => {
console.log(response);
});Set truto_upsert_drive_items: true to merge new selections with existing items instead of replacing them:
showFilePicker('onedrive', integratedAccountToken, {
truto_upsert_drive_items: true,
}).then((response) => {
console.log(response);
});For SharePoint and OneDrive, set truto_preselect_drive_items: true to open the picker with the items already stored on the integrated account selected:
showFilePicker('sharepoint', integratedAccountToken, {
truto_preselect_drive_items: true,
}).then((response) => {
console.log(response);
});