0.0.16 • Published 8 months ago
@unthread-io/node v0.0.16
unthread-node-client
Unthread API Client for Node
Install
With npm:
npm install @unthread-io/node
Usage
This package uses ES modules. Import and use the client as follows:
import { UnthreadClient } from "@unthread-io/node";
const unthreadClient = new UnthreadClient({
apiKey: "your-api-key-here",
baseUrl: "https://api.unthread.io/api" // Optional, this is the default
});
Automations
The client provides access to Automations functionality through two main components: Stores and Functions.
Stores
Stores allow you to manage key-value data storage:
// Get a store
const store = await unthreadClient.automations.stores.get("storeName");
// List all stores
const stores = await unthreadClient.automations.stores.list();
// Use transactions
const transaction = await unthreadClient.automations.stores.transaction("storeName");
await transaction.setValue("key", "value");
await transaction.commit();
// Direct operations
await unthreadClient.automations.stores.setValue("storeName", "key", "value");
const value = await unthreadClient.automations.stores.getValue("storeName", "key");
await unthreadClient.automations.stores.deleteValue("storeName", "key");
Functions
Functions allow you to manage and deploy automation code:
// Upsert a draft version
const draft = await unthreadClient.automations.functions.upsertDraftVersion({
code: "your function code here"
});
// Activate a version
await unthreadClient.automations.functions.activateVersion(draft.version);
// Deploy a new version (upsert and activate in one step)
const deployed = await unthreadClient.automations.functions.deployNewVersion({
code: "your function code here"
});
Error Handling
The client provides custom error classes for different types of API errors:
UnthreadApiError
: Base class for API errorsAuthorizationError
: For 401 and 403 errorsNotFoundError
: For resource not found errorsConflictError
: For transaction conflictsAlreadyCommittedError
: For attempting operations on already committed transactions
License
This project is licensed under the MIT License. See the LICENSE file for details.