brx-node SDK
Official Node.js SDK for BRX
brx-node SDK
The brx-node
package is the official Node.js SDK for interacting with the BRX platform. It provides a simple and intuitive interface for creating, managing, and executing BRKs.
Installation
Basic Usage
API Reference
BRX Class
The BRX
class is the main entry point for interacting with the BRX platform.
Constructor
accessToken
(required): Your BRX API keyoptions
(optional): Configuration optionsuse_brx_key
(default:true
): Whether to use the BRX API key for authenticationverbose
(default:false
): Enable verbose loggingsend_local
(default:false
): Use local API endpoint (for development)force_client
(default:false
): Force client-side WebSocketsilent
(default:false
): Disable welcome message
Methods
get
Fetches a BRK schema by its ID.
brxID
(required): The ID of the BRK to fetch- Returns: A promise that resolves to the BRK schema
run
Executes a BRK and returns the results.
query
(required): The BRK to executecallback
(optional): A callback function that will be called for each result- Returns: A promise that resolves to an array of results
create
Creates a new BRK.
modifyRequest
(required): The BRK creation request- Returns: A promise that resolves to the creation result
update
Updates an existing BRK.
modifyRequest
(required): The BRK update request- Returns: A promise that resolves to the update result
delete
Deletes a BRK.
modifyRequest
(required): The BRK deletion request- Returns: A promise that resolves to the deletion result
clone
Clones a BRK.
modifyRequest
(required): The BRK clone request- Returns: A promise that resolves to the clone result
execute
Low-level method for executing a BRK. In most cases, you should use run
instead.
query
(required): The BRK or query stream request to executecallback
(optional): A callback function that will be called for each result- Returns: A promise that resolves to an array of results
modify
Low-level method for modifying a BRK. In most cases, you should use create
, update
, delete
, or clone
instead.
modifyRequest
(required): The BRK modification request- Returns: A promise that resolves to the modification result
BRK Class
The BRK
class represents a BRK (BRX Knowledge Representation) that can be executed.
Constructor
BRKSchema
(optional): The BRK schemaBRXClient
(optional): The BRX client to use for execution
Properties
input
An object containing the input values for the BRK. You can set input values by assigning to properties of this object.
brxQuery
The internal representation of the BRK query. You should not modify this directly.
inprogress
Whether the BRK is currently being executed.
Methods
run
Executes the BRK using the associated BRX client.
callback
(optional): A callback function that will be called for each result- Returns: A promise that resolves to an array of results
updateBRK
Updates the internal BRK query with the current input values.
verbose
(optional): Enable verbose logging- Returns: A promise that resolves to an object containing the updated BRK query
Examples
Creating a BRK
Using a BRK with Dependencies
Error Handling
Advanced Usage
WebSocket Connections
The BRX client uses WebSockets for real-time communication with the BRX platform. You can customize the WebSocket behavior using the constructor options.
Custom Processing
You can customize how BRKs are processed by setting the processType
property in the processParams
object.
Working with Maps
The BRX SDK uses JavaScript Map
objects for certain properties. When serializing these objects to JSON, you need to use the mapReplacer
function.
Similarly, when deserializing JSON to objects with Map
properties, you need to use the mapReviver
function.
Troubleshooting
Common Issues
- Authentication Errors: Make sure your API key is correct and has not expired.
- Network Errors: Check your internet connection and firewall settings.
- Rate Limiting: The BRX API has rate limits. If you’re making too many requests, you may be temporarily blocked.
- Invalid BRK IDs: Make sure the BRK IDs you’re using exist and are accessible to your account.
Debugging
You can enable verbose logging to help debug issues:
This will log detailed information about WebSocket connections, requests, and responses.
Further Reading
- BRX API Reference
- [Core Concepts: BRK](/docs/Core Concepts/BRK)
- [Core Concepts: BRX Client](/docs/Core Concepts/BRXClient)
- [Core Concepts: Composability](/docs/Core Concepts/Composability)