ApiClient calls the Agreements API directly with that user’s delegated access token.
Prerequisites
- Node.js
>=18. - A public OAuth client ID that is already registered in the Developer Portal.
- The exact loopback redirect
http://127.0.0.1/callbackregistered for that client. - The authorization-server issuer and Agreements API base URL for the same Shodai environment.
Install the SDK
ApiClient from the package root and the delegated session types from the Node-only /oauth export.
Create and restore the session
The following example stores the complete rotated token set in an application-owned file. Replace these file operations with your platform’s secure storage when appropriate.loginWithLoopback() opens the consent page and waits for the registered loopback redirect. Later runs restore the saved token set, and tokenProvider() refreshes an expired access token when a refresh token is available.
Run the same application with --disconnect when the user disconnects.
Confirm the result
A successful first run opens the consent page, saves the delegated token set after authorization, and prints an authenticated Agreements API result. A later run reuses the saved session without opening the consent page. The lifecycle callbacks are both required for durable sessions:onTokensUpdatedsaves the complete token set after login and refresh-token rotation.restoreTokens()restores that saved set before the first API call.onTokensClearedremoves the saved set whenrevoke()disconnects the user.revoke()clears in-memory state and attempts persisted-state deletion even when server-side revocation cannot be confirmed.
revoke() as an incomplete disconnect: local storage deletion may have failed, remote revocation may be unconfirmed, or both failures may be present in an AggregateError. Keep the error visible to the user or operator instead of reporting an unconditional successful disconnect.
For constructor fields and exported symbols, see the TypeScript client reference.