SDK
Use the typed TypeScript client.
Use the client
The SDK is a typed client for the same operations. Method names match the operation names, inputs are checked as you type, and results are typed too.
import { createSdk } from '@seawatts/sdk/client';
const sdk = createSdk({
apiKey: process.env.SEAWATTS_API_KEY,
baseUrl: 'https://your-app.example.com',
});
const org = await sdk.org.current();
await sdk.org.updateName({ name: 'acme' });Handle errors
A failed call throws an SdkError. Its code is the same one the REST API returns, so you can branch on it; its message is safe to show.
import { SdkError } from '@seawatts/sdk/client';
try {
await sdk.org.updateName({ name: 'Not Valid' });
} catch (error) {
if (error instanceof SdkError && error.code === 'BAD_REQUEST') {
console.log(error.message);
}
}