Report an integration from Node.js
Use @hivekit/integration-sdk-node to report work from a Node.js process. This walkthrough registers a manual job and runs it from the command line. It validates three sample readings and reports their mean.
Before you start
- Use Node.js 22 or later. The package has no runtime dependencies and supports ES modules and CommonJS.
- Use a Hivekit server with the Integration Registry and execution snapshot encryption configured. Confirm that Data Imports is available in the app for the account that will review the run.
- Obtain a registration token with
Cand a runtime token withRP, both scoped to the job keysample-readings. See Registry authentication and permissions. - Set
HIVEKIT_REST_URLto the REST base URL, such ashttp://localhost:8090/v2/for local development. SetHIVEKIT_REGISTER_TOKENandHIVEKIT_RUN_TOKENto their raw bearer tokens through your environment or secret manager. The SDK appendsservice/integration/to the base URL. Use your deployment's HTTPS URL for remote connections.
Register a job
In a working directory for the example, install the package.
npm install @hivekit/integration-sdk-node
Save this as register-job.mjs. Run it during setup and again when the manifest changes. The runtime can use its own credentials and look up the existing job on subsequent runs.
import { IntegrationClient } from '@hivekit/integration-sdk-node';
const client = new IntegrationClient({
url: process.env.HIVEKIT_REST_URL,
token: process.env.HIVEKIT_REGISTER_TOKEN,
});
try {
const job = await client.registerJob('sample-readings', {
name: 'Sample Readings',
description: 'Validate readings and calculate their mean.',
kind: 'manual',
configuration: {
type: 'object',
additionalProperties: false,
properties: {
decimalPlaces: {
type: 'integer',
title: 'Decimal places',
enum: [0, 1, 2],
default: 1,
},
},
},
});
console.log('Registered job', job.key);
} finally {
await client.close();
}
node register-job.mjs
Report an execution
Save this as report-readings.mjs in the same directory. The SDK declares both steps when the execution starts. The example reports progress as each reading is checked and uses the execution's configuration to format the mean.
import { IntegrationClient } from '@hivekit/integration-sdk-node';
const client = new IntegrationClient({
url: process.env.HIVEKIT_REST_URL,
token: process.env.HIVEKIT_RUN_TOKEN,
});
const readings = [16.2, 17.6, 15.8];
try {
const job = await client.getJob('sample-readings');
const run = await job.startExecution(
[
{ key: 'validate', name: 'Validate readings', weight: 0.75 },
{ key: 'summarize', name: 'Summarize readings', weight: 0.25 },
],
{ metadata: { source: 'sample-readings' } },
);
console.log('Started run', run.id);
const validate = run.startStep('validate');
for (const [index, reading] of readings.entries()) {
if (!Number.isFinite(reading)) {
const reason = 'Expected a finite numeric reading';
await validate.fail(reason, { index });
await run.fail(reason);
throw new Error(reason);
}
validate.progress((index + 1) / readings.length);
}
await validate.complete();
const summarize = run.startStep('summarize');
const mean = readings.reduce((sum, reading) => sum + reading, 0) / readings.length;
summarize.info('Calculated mean', {
count: readings.length,
mean: Number(mean.toFixed(run.config.decimalPlaces)),
});
await summarize.complete();
await run.complete();
console.log('Completed run', run.id);
} finally {
await client.close();
}
node report-readings.mjs
Open Settings → Data Imports → Sample Readings → Runs in Hivekit. Expect a Succeeded run with two completed steps and a Calculated mean entry in Execution logs. With the default configuration the reported mean is 16.5. To exercise the failure path on a development deployment, change the second sample value to null and run the script again. Expect a new Failed run with an error log on Validate readings.
Adapt the SDK to your integration
| API | Use it for |
|---|---|
new IntegrationClient({ url, token, flushIntervalMs, requestTimeoutMs, onError }) | Connect to a Registry. Use a token string or a function that returns the current token, including asynchronously. Optional defaults are 1,000 ms between flushes and 10,000 ms per HTTP attempt. |
client.registerJob(key, manifest) | Create or update a job manifest under a stable key. |
client.getJob(key), client.listJobs({ key, afterKey, limit }) | Look up a job or list a page of jobs. For the next page, pass the last returned key as afterKey. The default limit is 100. |
await job.startExecution(steps, { metadata }) | Start a run and declare up to 1,000 steps with unique keys. Read its frozen configuration snapshot from run.config. A step's name defaults to its key and its weight defaults to 1. Use positive weights up to 1. |
run.startStep(key), step.progress(fraction) | Start a declared step and queue progress from 0 through 1. For example, step.progress(0.5) reports 50%. |
step.complete(), step.skip(reason), step.fail(reason, details) | Finish a running step. Await each call to observe delivery errors. |
run.debug(), run.info(), run.warn(), run.error() | Report a message and optional JSON-serializable details for the run. Call the same methods on a step to associate a message with it. |
run.complete(), run.fail(reason, details) | Flush pending reports and record the run outcome. Await the call. |
run.flush(), client.flush(), client.close() | Wait for queued reports to be delivered. Close also stops the SDK's background timers. Finish the run explicitly before closing. |
For CommonJS use const { IntegrationClient } = require('@hivekit/integration-sdk-node'); in place of the import. For a serverless invocation, create the client inside the handler and await close() before the handler returns. For a continuous process, keep the execution open while it is active and await the intended outcome and shutdown when the process stops gracefully.
Account for reporting failures
- The SDK mirrors logs to the process console immediately and sends them to Hivekit in batches. Pending reports live in memory. Enable your host's stdout and stderr capture to retain a separate copy of the logs.
- Await step and execution completion and call
flush()when your code needs a delivery barrier. Background reporting errors reachonErroror stderr. A failed delivery can be retried with a later flush or close. Log batches can contain duplicate lines after an ambiguous connection failure. - The SDK retries eligible transport and transient HTTP failures for reads, execution starts, heartbeats, step updates, and execution completion. Each invocation of
startExecution()starts a new run. An automatic retry of the same call reuses its internal request identity. Keep any retry and deduplication of actual data writes in your integration. - The per-execution queue is bounded at 10,000 reports and 8 MiB. A full queue throws. Flush before adding more reports. Logs use batches of up to 100 entries and 1 MiB, and a message can contain up to 16,384 UTF-8 bytes. Use finite JSON numbers and JavaScript-safe integers in values sent through the SDK.
- Use safe error summaries, log messages, metadata, and details. The SDK can serialize an
Errorwith its message and stack, so choose what you pass when failures can contain credentials, URLs with tokens, or sensitive records.
IntegrationApiError carries an HTTP status. A 403 usually means the token lacks an operation's capability. A job lookup can return 404 when the job is absent or hidden from the token. A 400 during start can mean a required configuration value is missing. A 503 mentioning integration encryption keys needs an administrator to check server setup. IntegrationTransportError indicates a connection failure or timeout. Confirm the REST base URL and preserve the run ID when investigating an ambiguous outcome.
Deregister only when retiring a job
The SDK's client.deregisterJob(key) requires a deployment that exposes DELETE service/integration/job/{jobId} and grants delete access. A token that looks up the job and deletes it needs RD on deployments with that capability. Deregistration permanently deletes the job, configuration, and run, step, and log history. Confirm the endpoint and permissions with your deployment administrator before using it.
For the data model and health rules, see Integration jobs, runs, and steps. For requests outside the SDK, see the Integration Registry API.