1.0.5 • Published 7 months ago
@buniflow/js v1.0.5
buniflow-js - JavaScript/TypeScript SDK for Buniflow REST APIs
- Documentation: https://buniflow.com/docs/reference/javascript/start
- TypeDoc: https://buniflow.github.io/buniflow-js/v2/
Usage
First of all, you need to install the library:
npm install @buniflow/jsThen you're able to import the library and establish the connection with the database:
import { BuniflowClient } from "@buniflow/js";
// Initialize the client
const client = new BuniflowClient({
baseUrl: "https://engine.example.com/",
apiKey: "{{api_key}}",
projectId: "{{project_id}}",
});You can now use the client to interact with the Buniflow API. Let's look at some examples:
Login
async function login() {
try {
const result = await client.auth.login("ngugindungu@gmail.com", "password");
console.log("Login successful:", result);
} catch (error) {
console.error("Login failed:", error);
}
}
login();Execute workflow
async function executeWorkflow() {
try {
const result = await client.engine.executeWorkflowByPath({
mode: "api",
run_mode: "production",
nodes: ["{{node_id}}"],
path: "/{{project_id}}/modules/{{module_id}}/workflows/{{workflow_id}}",
environment_id: "{{environment_id}}",
payload: {},
});
// Access node results
const nodeId = "{{node_id}}";
if (result.data[nodeId]) {
console.log("Node name:", result.data[nodeId].name);
console.log("Node data:", result.data[nodeId].data);
console.log("Is pending:", result.data[nodeId].isPending);
console.log("Is error:", result.data[nodeId].isError);
}
} catch (error) {
console.error("Workflow execution failed:", error);
}
}
executeWorkflow();UMD
You can use plain <script>s to import buniflow-js from CDNs, like:
<script src="https://cdn.jsdelivr.net/npm/@buniflow/js@2"></script>or even:
<script src="https://unpkg.com/@buniflow/js@2"></script>Then you can use it from a global buniflow variable:
<script>
const { BuniflowClient } = buniflow;
const buniflow = new BuniflowClient({
baseUrl: "https://engine.example.com/",
apiKey: "{{api_key}}",
projectId: "{{project_id}}",
});
console.log("Buniflow Instance: ", buniflow);
// ...
</script>ESM
You can use <script type="module"> to import buniflow-js from CDNs, like:
<script type="module">
import { BuniflowClient } from "https://cdn.jsdelivr.net/npm/@buniflow/js/+esm";
const client = new BuniflowClient({
baseUrl: "https://engine.example.com/",
apiKey: "{{api_key}}",
projectId: "{{project_id}}",
});
console.log("Buniflow Instance: ", buniflow);
// ...
</script>