The package @zerodot/node-sdk defines the node contract. Use it to write nodes and credential types.
For the full contract, see Node packages.
Install
Add the SDK and zod as peer dependencies:
npm install --save-peer @zerodot/node-sdk zod
Set the SDK range in package.json:
{ "zerodot": { "sdk": "^1.2" } }
SDK versions
SDK_VERSION is the contract version. In this release it is 1.7.0. A minor version only adds. A major version can break a package.
Zerodot checks the sdk range before it runs package code. A package with no range, or with a range that does not fit, does not load. The function satisfiesSdk(range) tells if the contract fits a range. It accepts a caret range (^1.4) or one exact version.
| SDK | Adds |
|---|---|
| 1.4 | Supply ports and supply nodes, nodes as agent tools. |
| 1.5 | Supplies for tool runs, run cache, close(), port showWhen. |
| 1.6 | kv: a key-value store for each workflow. |
| 1.7 | loadOptions: field options that load from a service. |
A node
Use defineNode. This node comes from the template (src/text-case.ts).
import { defineNode, isRecord } from "@zerodot/node-sdk";
import { z } from "zod";
const config = z.object({
field: z.string().min(1).default("text").meta({
title: "Field",
description: "The field of the input that has the text",
}),
});
export default defineNode({
type: "example.textCase",
label: "Text Case",
description: "Change text to upper, lower, or title case",
category: "data",
app: "Example",
icon: "TextIcon",
config,
defaultConfig: { field: "text" },
ports: { in: ["main"], out: ["main"] },
run({ config, input }) {
if (!isRecord(input)) throw new Error("The input must be an object");
const value = input[config.field];
if (typeof value !== "string") throw new Error(`The field "${config.field}" is not text`);
return { port: "main", data: { ...input, [config.field]: value.toUpperCase() } };
},
});
The config can hold expressions, for example {{ $input.name }}. Zerodot resolves them before run gets the config.
A credential type with a test
A credential type lists its fields and the secret fields. Zerodot keeps secret fields encrypted. The optional test() runs when the user clicks the test button. Throw an error when the credential does not work.
import type { CredentialTypeDefinition } from "@zerodot/node-sdk";
import { z } from "zod";
export const apiCredential: CredentialTypeDefinition = {
type: "example.api",
label: "Example API",
fields: z.object({
baseUrl: z.string().url(),
token: z.string().min(1),
}),
secretFields: ["token"],
icon: "Key01Icon",
async test(credential) {
const response = await fetch(String(credential.data.baseUrl), {
headers: { authorization: `Bearer ${String(credential.data.token)}` },
signal: AbortSignal.timeout(10_000),
});
if (!response.ok) throw new Error(`The API answered with status ${response.status}`);
},
};
A node uses the credential with credentialTypes: ["example.api"]. Then run gets credential.
Export both from src/index.ts:
export const nodes: NodeDefinition[] = [textCase, apiRequest];
export const credentialTypes: CredentialTypeDefinition[] = [apiCredential];
Contract parts
| Part | Use |
|---|---|
run |
Runs the node. Returns { port, data }. |
poll |
Checks a service on a schedule. |
listen |
Keeps a connection open and emits items. |
webhook |
Gets calls from outside. Has receive, and optional activate and deactivate. |
credentialTypes |
Names the credential types that the node uses. |
credential test() |
Checks a credential. |
loadOptions |
Loads field options from a service (SDK 1.7). |
kv |
A key-value store for the workflow (SDK 1.6). |
supplies |
Values from supply nodes (SDK 1.5). |
For examples of triggers, polling, and webhooks, see the official packages.
Field options from a service
From SDK 1.7, a node can have loadOptions. Each loader has a name. A config field uses the name in its meta:
pipelineId: z.string().meta({ title: "Pipeline", loadOptions: "pipelines" }),
A loader gets the config, the credential, and an abort signal. It returns a list of { label, value }. The loader runs on the server. A loader that takes more than 20 seconds fails. The user can always type a value instead. Community packages can use loaders.
Official-only features
These parts work only in official @zerodot/* packages. Only the Zerodot team publishes those packages.
- Supply nodes, supply ports, and supply modes (
supplies). kv(SDK 1.6). A community package does not getkv.
For limits of community packages, see Community package limits.