Cedalio
Search
K

TypeScript

The TypeScript SDK interact with Cedalio's API in a more intuitive way, whilst providing strong typing and easy support for Node and Browser environments.
npm version
The Typescript SDK is currently in Alpha. There might be breaking changes between versions

Installation

The SDK is installed via npm (or any other Node package manager)
npm i @cedalio/sdk-js

Create an SDK instance

To start working with our SDK, you must first create a CedalioSDK instance. The constructor requires a Project ID. You can get your Project ID from the Studio settings after creating your Project.
const cedalioSdk = new CedalioSDK({
projectId: 'Your project id'
});

Responses and Errors

All methods return an ApiResponse<T> object, where the generic T corresponds to the type of that method's response. If the method succeeds, a SuccessApiResponse<T> is returned. In case the method fails, an ErrorApiResponse is returned.
This responses are designed to provide you all the information needed to understand what happened with the request, whether it failed or not.
type SuccessApiResponse<T> = { status: number; ok: true; data: T };
type ErrorApiResponse = { status: number; ok: false; error: ApiError };
type ApiResponse<T> = SuccessApiResponse<T> | ErrorApiResponse;
An example of a successful response would be the following:
// Response type ApiResponse<VerifyAuthAPIResponse>
const response = await cedalioSdk.login({ address: 'The wallet address' });
console.log(response);
/*
{
ok: true,
status: 201,
data: {
token: 'The JWT authentication token'
}
}
}*/
While a failed response contains an error message and the payload received by the underlying API endpoint (solely for debugging purposes):
// Response type ApiResponse<VerifyAuthAPIResponse>
const response = await cedalioSdk.deploy({ schemaOwner: 'an address' });
console.log(response);
/*
{
ok: false,
status: 401,
error: {
message: 'The error message',
payload: {
schema_owner: 'an address'
}
}
}
}*/
If you are using TypeScript, you will have to check whether the request was successful via the ok property before being able to work with the response data/error.
const response = await cedalioSdk.login();
if (response.ok) {
// You can access `response.data` now.
} else {
// You can access `response.error` now.
}