@zerodot/node-sdk 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/dist/index.d.mts +531 -0
- package/dist/index.mjs +758 -0
- package/package.json +40 -3
- package/README.md +0 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Binary data in a node output. zerodot has no separate binary store, so the bytes are base64
|
|
4
|
+
* text under `binary.<property>` in the JSON output. The size limit of a node output applies.
|
|
5
|
+
*/
|
|
6
|
+
type BinaryData = {
|
|
7
|
+
data: string;
|
|
8
|
+
mimeType: string;
|
|
9
|
+
fileName?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function mimeTypeOf(fileName: string): string;
|
|
12
|
+
export declare function toBinary(bytes: Uint8Array, fileName: string, mimeType?: string): BinaryData;
|
|
13
|
+
/** The binary data that an earlier node put under `input.binary[property]`. */
|
|
14
|
+
export declare function readBinary(input: unknown, property: string): BinaryData;
|
|
15
|
+
declare const sandboxRequestSchema: z.ZodObject<{
|
|
16
|
+
code: z.ZodString;
|
|
17
|
+
scope: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
18
|
+
timeoutMs: z.ZodNumber;
|
|
19
|
+
maxOutputBytes: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
type SandboxRequest = z.infer<typeof sandboxRequestSchema>;
|
|
22
|
+
declare const SANDBOX_LOG_LEVELS: readonly ["log", "info", "warn", "error", "debug"];
|
|
23
|
+
/** One `console` call in the code. */
|
|
24
|
+
type CodeLog = {
|
|
25
|
+
level: (typeof SANDBOX_LOG_LEVELS)[number];
|
|
26
|
+
message: string;
|
|
27
|
+
};
|
|
28
|
+
type SandboxClient = {
|
|
29
|
+
/**
|
|
30
|
+
* Resolves with the value the code returned. Throws `SandboxError` when the code fails.
|
|
31
|
+
* `onLogs` gets the `console` calls of the code, also when the code fails.
|
|
32
|
+
*/
|
|
33
|
+
run(request: SandboxRequest, signal: AbortSignal, onLogs?: (logs: CodeLog[]) => void): Promise<unknown>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Rules that decide when a config field shows in the editor. A condition maps a config key to the
|
|
37
|
+
* values that it accepts. A value is a plain value, or an operator object `{ _cnd: { gte: 1.1 } }`.
|
|
38
|
+
* All keys of one condition must match. A list of conditions needs one match.
|
|
39
|
+
*/
|
|
40
|
+
type FieldCondition = Record<string, unknown[]>;
|
|
41
|
+
type ShowRules = {
|
|
42
|
+
showWhen?: FieldCondition | FieldCondition[];
|
|
43
|
+
/** The field hides when one of these conditions holds. This wins over `showWhen`. */
|
|
44
|
+
hideWhen?: FieldCondition | FieldCondition[];
|
|
45
|
+
};
|
|
46
|
+
/** A row as workflows see it: the system fields, then the columns. A missing value is null. */
|
|
47
|
+
type TableRow = {
|
|
48
|
+
id: string;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
[column: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
declare const FILTER_OPS: readonly ["eq", "neq", "gt", "gte", "lt", "lte", "in", "contains", "isNull"];
|
|
54
|
+
type FilterOp = (typeof FILTER_OPS)[number];
|
|
55
|
+
type FilterCondition = {
|
|
56
|
+
field: string;
|
|
57
|
+
op: FilterOp;
|
|
58
|
+
value?: unknown;
|
|
59
|
+
};
|
|
60
|
+
type Filter = FilterCondition | {
|
|
61
|
+
and: Filter[];
|
|
62
|
+
} | {
|
|
63
|
+
or: Filter[];
|
|
64
|
+
};
|
|
65
|
+
declare const sortSchema: z.ZodArray<z.ZodObject<{
|
|
66
|
+
field: z.ZodString;
|
|
67
|
+
direction: z.ZodDefault<z.ZodEnum<{
|
|
68
|
+
asc: "asc";
|
|
69
|
+
desc: "desc";
|
|
70
|
+
}>>;
|
|
71
|
+
}, z.core.$strip>>;
|
|
72
|
+
type Sort = z.output<typeof sortSchema>;
|
|
73
|
+
type RowQuery = {
|
|
74
|
+
filter?: Filter;
|
|
75
|
+
sort?: Sort;
|
|
76
|
+
limit?: number;
|
|
77
|
+
cursor?: string | null;
|
|
78
|
+
};
|
|
79
|
+
type RowPage = {
|
|
80
|
+
rows: TableRow[];
|
|
81
|
+
nextCursor: string | null;
|
|
82
|
+
};
|
|
83
|
+
type UpdateInput = {
|
|
84
|
+
filter?: Filter;
|
|
85
|
+
/** Needed when there is no filter. */
|
|
86
|
+
all?: boolean;
|
|
87
|
+
set?: Record<string, unknown>;
|
|
88
|
+
/** Adds to number columns. The database does it in one statement. */
|
|
89
|
+
increment?: Record<string, number>;
|
|
90
|
+
};
|
|
91
|
+
type UpsertInput = {
|
|
92
|
+
/** A unique column. The value comes from `row`. */
|
|
93
|
+
column: string;
|
|
94
|
+
row: Record<string, unknown>;
|
|
95
|
+
increment?: Record<string, number>;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* What the table nodes use. The database package implements it.
|
|
99
|
+
* `table` is the id or the name of a table.
|
|
100
|
+
*/
|
|
101
|
+
type TableStore = {
|
|
102
|
+
insert(table: string, rows: Record<string, unknown>[]): Promise<TableRow[]>;
|
|
103
|
+
query(table: string, query: RowQuery): Promise<RowPage>;
|
|
104
|
+
get(table: string, by: {
|
|
105
|
+
field: string;
|
|
106
|
+
value: unknown;
|
|
107
|
+
}): Promise<TableRow | null>;
|
|
108
|
+
/** `rows` holds up to 100 of the changed rows. `count` is the total. */
|
|
109
|
+
update(table: string, input: UpdateInput): Promise<{
|
|
110
|
+
count: number;
|
|
111
|
+
rows: TableRow[];
|
|
112
|
+
}>;
|
|
113
|
+
upsert(table: string, input: UpsertInput): Promise<{
|
|
114
|
+
row: TableRow;
|
|
115
|
+
created: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
delete(table: string, input: {
|
|
118
|
+
filter?: Filter;
|
|
119
|
+
all?: boolean;
|
|
120
|
+
}): Promise<{
|
|
121
|
+
count: number;
|
|
122
|
+
}>;
|
|
123
|
+
};
|
|
124
|
+
/** The workflow that a sub-workflow node runs: one of the organization, or a graph in the config. */
|
|
125
|
+
type SubWorkflowSource = {
|
|
126
|
+
kind: "database";
|
|
127
|
+
workflowId: string;
|
|
128
|
+
} | {
|
|
129
|
+
kind: "parameter";
|
|
130
|
+
graph: unknown;
|
|
131
|
+
};
|
|
132
|
+
type SubWorkflowRunner = (source: SubWorkflowSource, input: unknown, options: {
|
|
133
|
+
wait: boolean;
|
|
134
|
+
}) => Promise<unknown>;
|
|
135
|
+
type NodeCategory = "trigger" | "core" | "logic" | "data" | "flow" | "code" | "integration";
|
|
136
|
+
/** A credential after decryption. The type is the credential type, for example "http.bearer". */
|
|
137
|
+
type ResolvedCredential = {
|
|
138
|
+
type: string;
|
|
139
|
+
data: Record<string, unknown>;
|
|
140
|
+
};
|
|
141
|
+
type NodeRunContext<Config> = {
|
|
142
|
+
/** Config with expressions resolved and checked against the Zod schema. */
|
|
143
|
+
config: Config;
|
|
144
|
+
/** Output data of the parent node. For a trigger node, the trigger input. */
|
|
145
|
+
input: unknown;
|
|
146
|
+
/** Decrypted credential, if the node has one. */
|
|
147
|
+
credential: ResolvedCredential | null;
|
|
148
|
+
signal: AbortSignal;
|
|
149
|
+
/** Plain values that the expression language can read: $trigger, $node, $input, $vars, $run, $resumeUrl. */
|
|
150
|
+
scope: Record<string, unknown>;
|
|
151
|
+
/** Adds `console` logs of the node to the result of this node. They show in the run. */
|
|
152
|
+
log?: (logs: CodeLog[]) => void;
|
|
153
|
+
/** The code sandbox, or null when the worker has none. */
|
|
154
|
+
sandbox: SandboxClient | null;
|
|
155
|
+
/** Data tables of the project, or null when the worker has none. */
|
|
156
|
+
tables: TableStore | null;
|
|
157
|
+
/**
|
|
158
|
+
* Address that answers this node while it waits. A person opens it, and the run goes on with
|
|
159
|
+
* their answer as the node output. Not set when the worker does not know the public address.
|
|
160
|
+
*/
|
|
161
|
+
resumeUrl?: string | null;
|
|
162
|
+
/**
|
|
163
|
+
* Runs another workflow of the same organization with `input` as its trigger input. With
|
|
164
|
+
* `wait: true` it returns the output of the last node that ran. With `wait: false` it only
|
|
165
|
+
* starts the run and returns `{ runId }`. Null when the worker cannot run a sub-workflow.
|
|
166
|
+
*/
|
|
167
|
+
runWorkflow?: SubWorkflowRunner | null;
|
|
168
|
+
/**
|
|
169
|
+
* True when the data came back along a loop: the edge into this node starts at a node that
|
|
170
|
+
* this node feeds, directly or through other nodes. False for a first entry and for a trigger.
|
|
171
|
+
*/
|
|
172
|
+
loopBack?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* What this node returned as `state` the last time it ran in this run. Only for a node with
|
|
175
|
+
* `stateful: true`. It is not kept when the run stops, because the engine builds it again.
|
|
176
|
+
*/
|
|
177
|
+
state?: unknown;
|
|
178
|
+
};
|
|
179
|
+
export declare const FORM_FIELD_TYPES: readonly ["text", "number", "email", "textarea", "dropdown", "checkbox", "radio", "password", "date"];
|
|
180
|
+
/** A field of the page that a person fills in to answer a node that waits. */
|
|
181
|
+
type WaitFormField = {
|
|
182
|
+
fieldLabel: string;
|
|
183
|
+
/** The key of the answer in the output. Default: the label. */
|
|
184
|
+
key?: string;
|
|
185
|
+
fieldType?: (typeof FORM_FIELD_TYPES)[number];
|
|
186
|
+
placeholder?: string;
|
|
187
|
+
requiredField?: boolean;
|
|
188
|
+
/** For dropdown, checkbox, and radio. */
|
|
189
|
+
fieldOptions?: {
|
|
190
|
+
values: {
|
|
191
|
+
option: string;
|
|
192
|
+
}[];
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
type WaitForm = {
|
|
196
|
+
title?: string;
|
|
197
|
+
description?: string;
|
|
198
|
+
buttonLabel?: string;
|
|
199
|
+
fields: WaitFormField[];
|
|
200
|
+
};
|
|
201
|
+
type NodeResult = {
|
|
202
|
+
port: string;
|
|
203
|
+
data: unknown;
|
|
204
|
+
/**
|
|
205
|
+
* Epoch ms. The node is done, but the run must not go on before this time.
|
|
206
|
+
* The engine stops the run and the worker resumes it later. Nothing waits in memory.
|
|
207
|
+
*/
|
|
208
|
+
waitUntil?: number;
|
|
209
|
+
/**
|
|
210
|
+
* The answer to the HTTP request that started the run. A "respond to webhook" node sets it.
|
|
211
|
+
* The worker passes it to the web app, which holds the request open.
|
|
212
|
+
*/
|
|
213
|
+
respond?: RunResponse;
|
|
214
|
+
/**
|
|
215
|
+
* Kept in memory for the next run of this node in the same run (a loop). Only for a node with
|
|
216
|
+
* `stateful: true`. It never goes to the database.
|
|
217
|
+
*/
|
|
218
|
+
state?: unknown;
|
|
219
|
+
};
|
|
220
|
+
/** The answer to a webhook request: status, headers, and body. */
|
|
221
|
+
type RunResponse = {
|
|
222
|
+
status: number;
|
|
223
|
+
headers: Record<string, string>;
|
|
224
|
+
body: unknown;
|
|
225
|
+
};
|
|
226
|
+
/** A request to the webhook address of a trigger: `/hooks/:token`. */
|
|
227
|
+
type WebhookRequest = {
|
|
228
|
+
method: string;
|
|
229
|
+
headers: Record<string, string>;
|
|
230
|
+
query: Record<string, string>;
|
|
231
|
+
body: unknown;
|
|
232
|
+
/** The body as text, before it was parsed. */
|
|
233
|
+
rawBody?: string;
|
|
234
|
+
/** The body bytes as base64. The Webhook node saves them as binary data. */
|
|
235
|
+
bodyBase64?: string;
|
|
236
|
+
/** The address of the caller. Set only when the server trusts the proxy headers. */
|
|
237
|
+
ip?: string | null;
|
|
238
|
+
};
|
|
239
|
+
/** What a trigger node says about a request. `response` replaces the default answer of the route. */
|
|
240
|
+
type WebhookVerdict = {
|
|
241
|
+
verdict: "accept";
|
|
242
|
+
input: unknown;
|
|
243
|
+
response?: {
|
|
244
|
+
status: number;
|
|
245
|
+
body: unknown;
|
|
246
|
+
};
|
|
247
|
+
} | {
|
|
248
|
+
verdict: "ignore";
|
|
249
|
+
response?: {
|
|
250
|
+
status: number;
|
|
251
|
+
body: unknown;
|
|
252
|
+
};
|
|
253
|
+
} | {
|
|
254
|
+
verdict: "forbidden";
|
|
255
|
+
status?: number;
|
|
256
|
+
headers?: Record<string, string>;
|
|
257
|
+
};
|
|
258
|
+
/** What a trigger node gets when it handles a request, or when its workflow starts or stops. */
|
|
259
|
+
type WebhookContext<Config = Record<string, unknown>> = {
|
|
260
|
+
config: Config;
|
|
261
|
+
credential: ResolvedCredential | null;
|
|
262
|
+
/** Address of the webhook of this trigger, for example `https://zerodot.example/hooks/abc`. */
|
|
263
|
+
url: string;
|
|
264
|
+
workflow: {
|
|
265
|
+
id: string;
|
|
266
|
+
name: string;
|
|
267
|
+
};
|
|
268
|
+
node: {
|
|
269
|
+
id: string;
|
|
270
|
+
name: string;
|
|
271
|
+
};
|
|
272
|
+
/** Data that the node kept before. A node writes it by returning it from `activate` or `deactivate`. */
|
|
273
|
+
state: unknown;
|
|
274
|
+
signal: AbortSignal;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* A trigger that gets requests at its webhook address. `receive` checks a request and gives the
|
|
278
|
+
* trigger input of the run. `activate` and `deactivate` register and remove the webhook at
|
|
279
|
+
* another service. They return the new `state`.
|
|
280
|
+
*/
|
|
281
|
+
type NodeWebhook = {
|
|
282
|
+
receive(ctx: WebhookContext & {
|
|
283
|
+
request: WebhookRequest;
|
|
284
|
+
}): Promise<WebhookVerdict>;
|
|
285
|
+
activate?(ctx: WebhookContext): Promise<unknown>;
|
|
286
|
+
deactivate?(ctx: WebhookContext): Promise<unknown>;
|
|
287
|
+
};
|
|
288
|
+
/** What a polling trigger gets on each tick. */
|
|
289
|
+
type PollContext<Config = Record<string, unknown>> = {
|
|
290
|
+
config: Config;
|
|
291
|
+
credential: ResolvedCredential | null;
|
|
292
|
+
/** What the last poll returned as `cursor`. Null on the first poll after activation. */
|
|
293
|
+
cursor: unknown;
|
|
294
|
+
/** True on the first poll after activation. The items of this poll start no runs. */
|
|
295
|
+
firstPoll: boolean;
|
|
296
|
+
workflow: {
|
|
297
|
+
id: string;
|
|
298
|
+
name: string;
|
|
299
|
+
};
|
|
300
|
+
node: {
|
|
301
|
+
id: string;
|
|
302
|
+
name: string;
|
|
303
|
+
};
|
|
304
|
+
signal: AbortSignal;
|
|
305
|
+
};
|
|
306
|
+
/** One new thing at another service. Each item starts one run. */
|
|
307
|
+
type PollItem = {
|
|
308
|
+
/** Stable id of the item. The engine skips a key it has seen, so the same item starts one run. */
|
|
309
|
+
key: string;
|
|
310
|
+
/** The trigger input of the run. */
|
|
311
|
+
data: unknown;
|
|
312
|
+
};
|
|
313
|
+
type PollResult = {
|
|
314
|
+
/** New items, oldest first. */
|
|
315
|
+
items: PollItem[];
|
|
316
|
+
/** Kept and given back to the next poll. Not changed when the poll throws. */
|
|
317
|
+
cursor: unknown;
|
|
318
|
+
};
|
|
319
|
+
/** What a listening trigger gets when the worker starts it. */
|
|
320
|
+
type ListenContext<Config = Record<string, unknown>> = {
|
|
321
|
+
config: Config;
|
|
322
|
+
credential: ResolvedCredential | null;
|
|
323
|
+
workflow: {
|
|
324
|
+
id: string;
|
|
325
|
+
name: string;
|
|
326
|
+
};
|
|
327
|
+
node: {
|
|
328
|
+
id: string;
|
|
329
|
+
name: string;
|
|
330
|
+
};
|
|
331
|
+
/** Aborts when the worker stops. */
|
|
332
|
+
signal: AbortSignal;
|
|
333
|
+
/**
|
|
334
|
+
* Starts one production run. The `key` is stable for one event, so the same event starts
|
|
335
|
+
* one run. Resolves when the run is stored. Throws when the run cannot be stored.
|
|
336
|
+
*/
|
|
337
|
+
emit(item: PollItem): Promise<void>;
|
|
338
|
+
/** Reports a problem of the connection. The trigger shows it as its last error. */
|
|
339
|
+
fail(error: Error): void;
|
|
340
|
+
};
|
|
341
|
+
/** What a listening trigger gives back. The worker calls `close` when the trigger stops. */
|
|
342
|
+
type ListenHandle = {
|
|
343
|
+
/**
|
|
344
|
+
* `remove` is true when the workflow is not active any more, or the trigger changed. The node
|
|
345
|
+
* then removes what it made at another service. It is false when only the worker stops.
|
|
346
|
+
*/
|
|
347
|
+
close(options: {
|
|
348
|
+
remove: boolean;
|
|
349
|
+
}): Promise<void>;
|
|
350
|
+
};
|
|
351
|
+
/** The most items one poll may return. A poll that returns more fails and the cursor stays. */
|
|
352
|
+
export declare const POLL_MAX_ITEMS = 1000;
|
|
353
|
+
type NodeDefinition<Schema extends z.ZodType = z.ZodType> = {
|
|
354
|
+
type: string;
|
|
355
|
+
label: string;
|
|
356
|
+
/** One line under the name in the Add node list. */
|
|
357
|
+
description?: string;
|
|
358
|
+
category: NodeCategory;
|
|
359
|
+
/**
|
|
360
|
+
* Rows of the Add node list for this node, one for each thing it does, for example one for each
|
|
361
|
+
* operation. A row adds the node with `config` on top of the default config.
|
|
362
|
+
*/
|
|
363
|
+
actions?: {
|
|
364
|
+
label: string;
|
|
365
|
+
config: Record<string, unknown>;
|
|
366
|
+
}[];
|
|
367
|
+
/** App the node belongs to, for example "Postgres". The Add node list shows one row for the app. */
|
|
368
|
+
app?: string;
|
|
369
|
+
/** Name of a Lucide icon, in PascalCase, for example "Globe". The editor shows it. */
|
|
370
|
+
icon: string;
|
|
371
|
+
/** Image of the node, as a data URL. The editor shows it in place of `icon`. */
|
|
372
|
+
iconUrl?: string;
|
|
373
|
+
config: Schema;
|
|
374
|
+
/** Config for a node that the user just added. */
|
|
375
|
+
defaultConfig: z.input<Schema>;
|
|
376
|
+
/** Credential types this node accepts. The user picks one credential of these types. */
|
|
377
|
+
credentialTypes?: string[];
|
|
378
|
+
/**
|
|
379
|
+
* When a credential type applies, by config value. For example `{ "http.basic": { showWhen:
|
|
380
|
+
* { authentication: ["basic"] } } }`. A type with no rule always applies. The editor shows only
|
|
381
|
+
* the types that apply. The run accepts every type in `credentialTypes`.
|
|
382
|
+
*/
|
|
383
|
+
credentialRules?: Record<string, ShowRules>;
|
|
384
|
+
/** Short text under the node name in the editor. Config can hold unresolved expressions. */
|
|
385
|
+
subtitle?(config: Record<string, unknown>): string | undefined;
|
|
386
|
+
ports: {
|
|
387
|
+
in: string[];
|
|
388
|
+
out: string[];
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Input ports that depend on the config (a merge node has one port for each input). Without
|
|
392
|
+
* it the node has `ports.in`. An edge into a port that this list does not have is ignored by
|
|
393
|
+
* the engine and reported by the graph check.
|
|
394
|
+
*/
|
|
395
|
+
inPorts?(config: Record<string, unknown>): string[];
|
|
396
|
+
/**
|
|
397
|
+
* A join node waits for all of its parents. Its input is an object with the data of each
|
|
398
|
+
* input port, for example `{ input1, input2 }`. A parent that was skipped sends no data.
|
|
399
|
+
*/
|
|
400
|
+
join?: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* The node keeps `state` between its runs in one run (a loop counter). When a stopped run
|
|
403
|
+
* goes on, the engine runs the node again with its saved inputs to build the state again, and
|
|
404
|
+
* keeps the saved result. So `run` must have no side effects and must give the same answer for
|
|
405
|
+
* the same inputs.
|
|
406
|
+
*/
|
|
407
|
+
stateful?: boolean;
|
|
408
|
+
/** Config keys (top level) whose text is not an expression. The engine leaves `{{ }}` as it is. */
|
|
409
|
+
rawConfigKeys?: string[];
|
|
410
|
+
/**
|
|
411
|
+
* For a node that waits for a person: the form that the resume page shows, or null when
|
|
412
|
+
* the node needs no form (a click on a button is the answer, as `?approved=true`).
|
|
413
|
+
*/
|
|
414
|
+
waitForm?(config: Record<string, unknown>): WaitForm | null;
|
|
415
|
+
/**
|
|
416
|
+
* For a node that waits for an HTTP call to its resume address. Returns true when the config
|
|
417
|
+
* asks for it. Any method works. The method, headers, query, and body of the call are the
|
|
418
|
+
* node output. The address is also in the expression scope as `$resumeUrl["Node name"]`.
|
|
419
|
+
*/
|
|
420
|
+
waitsForCallback?(config: Record<string, unknown>): boolean;
|
|
421
|
+
/** For a trigger node with a webhook that needs its own checks or registration. */
|
|
422
|
+
webhook?: NodeWebhook;
|
|
423
|
+
/**
|
|
424
|
+
* For a trigger node that asks another service for news. The worker calls it on a timer
|
|
425
|
+
* (config key `intervalSeconds`, in seconds) while the workflow is active.
|
|
426
|
+
*/
|
|
427
|
+
poll?(ctx: PollContext<z.output<Schema>>): Promise<PollResult>;
|
|
428
|
+
/**
|
|
429
|
+
* For a trigger node that gets events through a connection that stays open. The worker calls
|
|
430
|
+
* it when the workflow is active, and keeps the handle until the trigger stops.
|
|
431
|
+
*/
|
|
432
|
+
listen?(ctx: ListenContext<z.output<Schema>>): Promise<ListenHandle>;
|
|
433
|
+
/** Output ports that depend on the config (a switch has one port for each case). */
|
|
434
|
+
outPorts?(config: Record<string, unknown>): string[];
|
|
435
|
+
run(ctx: NodeRunContext<z.output<Schema>>): Promise<NodeResult> | NodeResult;
|
|
436
|
+
};
|
|
437
|
+
export declare function defineNode<Schema extends z.ZodType>(definition: NodeDefinition<Schema>): NodeDefinition<Schema>;
|
|
438
|
+
/** How the client sends its id and secret to the token URL. */
|
|
439
|
+
type OAuth2Authentication = "header" | "body";
|
|
440
|
+
type OAuth2Config = {
|
|
441
|
+
authUrl: string;
|
|
442
|
+
tokenUrl: string;
|
|
443
|
+
scopes: string[];
|
|
444
|
+
/** Extra query parameters for the authorize URL, for example `access_type=offline`. */
|
|
445
|
+
authQuery?: Record<string, string>;
|
|
446
|
+
authentication: OAuth2Authentication;
|
|
447
|
+
pkce?: boolean;
|
|
448
|
+
};
|
|
449
|
+
type OAuth2Resolver = (data: Record<string, unknown>) => OAuth2Config | null;
|
|
450
|
+
type CredentialTypeDefinition = {
|
|
451
|
+
type: string;
|
|
452
|
+
label: string;
|
|
453
|
+
fields: z.ZodObject<Record<string, z.ZodType<string | undefined>>>;
|
|
454
|
+
/** Fields the form shows as password inputs. The form never shows a saved value of any field. */
|
|
455
|
+
secretFields: string[];
|
|
456
|
+
/** Fields that only the server sets. The form hides them, and a client cannot write them. */
|
|
457
|
+
serverFields?: string[];
|
|
458
|
+
/**
|
|
459
|
+
* An OAuth2 credential. A preset has fixed endpoints. A function builds the endpoints from the
|
|
460
|
+
* credential data (for example a server address). `"custom"` reads `authUrl`, `tokenUrl`,
|
|
461
|
+
* `scope` and `authentication` from the credential data.
|
|
462
|
+
*/
|
|
463
|
+
oauth2?: OAuth2Config | OAuth2Resolver | "custom";
|
|
464
|
+
/** Lucide icon name. */
|
|
465
|
+
icon?: string;
|
|
466
|
+
/** Image URL. It replaces `icon`. */
|
|
467
|
+
iconUrl?: string;
|
|
468
|
+
/**
|
|
469
|
+
* Checks a saved credential, for the "Test" button of the credential form. It throws with a
|
|
470
|
+
* short message when the credential does not work. zerodot removes secrets from the message.
|
|
471
|
+
*/
|
|
472
|
+
test?(credential: ResolvedCredential): Promise<void>;
|
|
473
|
+
};
|
|
474
|
+
/** A string with one `` and nothing else keeps the value type. Otherwise the result is text. */
|
|
475
|
+
export declare function resolveTemplate(input: string, scope: Record<string, unknown>): unknown;
|
|
476
|
+
/** Resolve every string inside a config value. Errors carry the path to the bad value. */
|
|
477
|
+
export declare function resolveConfig(value: unknown, scope: Record<string, unknown>, path?: string): unknown;
|
|
478
|
+
/**
|
|
479
|
+
* The shape of a nested field (a collection or a fixed collection), as plain data. A node writes
|
|
480
|
+
* it into the JSON Schema of its config. The editor draws a form from it.
|
|
481
|
+
* A key of a condition that starts with "/" reads from the top level of the config.
|
|
482
|
+
*/
|
|
483
|
+
type FieldSpec = {
|
|
484
|
+
name: string;
|
|
485
|
+
label: string;
|
|
486
|
+
kind: "string" | "number" | "boolean" | "options" | "filter" | "collection" | "fixed";
|
|
487
|
+
description?: string;
|
|
488
|
+
placeholder?: string;
|
|
489
|
+
default?: unknown;
|
|
490
|
+
multiline?: boolean;
|
|
491
|
+
options?: {
|
|
492
|
+
value: string | number | boolean;
|
|
493
|
+
label: string;
|
|
494
|
+
hint?: string;
|
|
495
|
+
}[];
|
|
496
|
+
show?: FieldCondition | FieldCondition[];
|
|
497
|
+
hide?: FieldCondition;
|
|
498
|
+
/** `collection`: the fields that the user can add. */
|
|
499
|
+
fields?: FieldSpec[];
|
|
500
|
+
/** `fixed`: the groups. A group holds a list when `multiple` is set, or one object. */
|
|
501
|
+
groups?: {
|
|
502
|
+
name: string;
|
|
503
|
+
label: string;
|
|
504
|
+
fields: FieldSpec[];
|
|
505
|
+
}[];
|
|
506
|
+
multiple?: boolean;
|
|
507
|
+
};
|
|
508
|
+
/** One item of a node run: a plain object. */
|
|
509
|
+
type Item = Record<string, unknown>;
|
|
510
|
+
export declare const isRecord: (value: unknown) => value is Item;
|
|
511
|
+
/** The items of a node run. A list is the items. One object is one item. Null is one empty item. */
|
|
512
|
+
export declare function toItems(input: unknown): Item[];
|
|
513
|
+
/**
|
|
514
|
+
* Reads an icon file of a package and returns it as a data URL, for `iconUrl` of a node or a
|
|
515
|
+
* credential type. `from` is `import.meta.url` of the file that calls it, and `path` is relative
|
|
516
|
+
* to that file, for example `fileIcon(import.meta.url, "./redis.svg")`. The icon file must be in
|
|
517
|
+
* the `files` of the package.
|
|
518
|
+
*/
|
|
519
|
+
export declare function fileIcon(from: string, path: string): string;
|
|
520
|
+
/**
|
|
521
|
+
* Version of the node contract (the shape of `NodeDefinition` and what a node can use).
|
|
522
|
+
* A minor version only adds. A major version can break a node package.
|
|
523
|
+
*/
|
|
524
|
+
export declare const SDK_VERSION = "1.1.0";
|
|
525
|
+
/**
|
|
526
|
+
* True when `version` fits `range`. A range is a caret range (`^1.4`, `^1.4.2`) or one exact
|
|
527
|
+
* version (`1.4.2`). A caret range allows the same major version, from the given version up.
|
|
528
|
+
* For major 0 it allows the same minor version only, as npm does.
|
|
529
|
+
*/
|
|
530
|
+
export declare function satisfiesSdk(range: string, version?: string): boolean;
|
|
531
|
+
export type { BinaryData, CredentialTypeDefinition, FieldSpec, Item, ListenContext, ListenHandle, NodeCategory, NodeDefinition, NodeResult, NodeRunContext, NodeWebhook, OAuth2Config, PollContext, PollItem, PollResult, ResolvedCredential, ShowRules, WaitForm, WaitFormField, WebhookContext, WebhookRequest, WebhookVerdict };
|