@engini/sdk 0.29.0 → 0.31.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/README.md +65 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.js +9 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.js +33 -0
- package/dist/http.js +17 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +3 -2
- package/dist/pagination.d.ts +15 -0
- package/dist/pagination.js +22 -0
- package/dist/resources/authProviders.d.ts +5 -2
- package/dist/resources/authProviders.js +6 -2
- package/dist/resources/executions.d.ts +63 -0
- package/dist/resources/executions.js +101 -0
- package/dist/resources/folders.d.ts +38 -0
- package/dist/resources/folders.js +45 -0
- package/dist/resources/index.d.ts +6 -0
- package/dist/resources/index.js +3 -0
- package/dist/resources/workflows.d.ts +101 -0
- package/dist/resources/workflows.js +119 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -198,6 +198,71 @@ for await (const event of client.triggers.subscribe({
|
|
|
198
198
|
`client.toolset(...)` builds a local toolset (no I/O until used) or loads a server one via
|
|
199
199
|
`client.toolset({ toolsetId })`.
|
|
200
200
|
|
|
201
|
+
## Executions
|
|
202
|
+
|
|
203
|
+
`client.executions` is the read-only run history of workflows, table automations and
|
|
204
|
+
business rules (no rerun):
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
// Every failed run of one workflow. With no `top` this follows `nextCursor` until it is
|
|
208
|
+
// absent; pass `top` for one page, or `listPage` to also get `nextCursor` back.
|
|
209
|
+
const failed = await client.executions.list({ workflowId: 123, status: ["failed"] });
|
|
210
|
+
const page = await client.executions.listPage({ top: 20, cursor: previous.nextCursor ?? undefined });
|
|
211
|
+
|
|
212
|
+
const run = await client.executions.get(4567);
|
|
213
|
+
const steps = await client.executions.log(4567); // throws EnginiAPIError on 410 (retention passed)
|
|
214
|
+
const payloads = await client.executions.data(4567, 3, { type: "response" }); // drains, 10 per page
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Sorting by `closedAt` (or several keys) has no cursor on the server, so `list` drains those
|
|
218
|
+
by `offset` instead.
|
|
219
|
+
|
|
220
|
+
## Building workflows
|
|
221
|
+
|
|
222
|
+
`client.workflows` is the workflow builder: look up what a plan may use, dry-run it, then
|
|
223
|
+
create or update a workflow from it. A workflow is always created turned off, and writes
|
|
224
|
+
need a workspace-scoped API key.
|
|
225
|
+
|
|
226
|
+
`workflows.list` and `folders.list` find the ids a plan or an edit needs. With no `top` they drain
|
|
227
|
+
every match (100 per page); with `top` they return one page, and `listPage` also returns
|
|
228
|
+
`totalCount`. `name` is a case-insensitive substring match, so compare it yourself for an exact one.
|
|
229
|
+
Rows carry no steps: read a workflow back with `getPlan`. `folders.list` lists workflow folders only.
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
const folders = await client.folders.list({ name: "Sales" }); // substring match
|
|
233
|
+
const sales = folders.find((f) => f.name === "Sales"); // pick the exact name yourself
|
|
234
|
+
const leads = await client.workflows.list({ name: "lead alert", folderId: Number(sales!.id) });
|
|
235
|
+
const firstPage = await client.workflows.listPage({ top: 20 }); // { items, totalCount, offset, top }
|
|
236
|
+
|
|
237
|
+
const hits = await client.workflows.searchCatalog({ q: "post message", app: "slack" });
|
|
238
|
+
const schema = await client.workflows.getSchema(hits[0].slug);
|
|
239
|
+
const connections = await client.workflows.listConnections({ app: "slack" });
|
|
240
|
+
|
|
241
|
+
const compiled = await client.workflows.compile({ plan }); // a plan with errors is returned, not thrown
|
|
242
|
+
if (!compiled.hasErrors) {
|
|
243
|
+
const { workflowId, revisionId } = await client.workflows.create({ plan });
|
|
244
|
+
await client.workflows.update(workflowId, { plan: edited, expectedRevisionId: revisionId });
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Also `getOptions(slug, { field, connectionId, dependsOn })`, `listTables()`,
|
|
249
|
+
`listTableColumns(tableId)` and `getPlan(workflowId)`.
|
|
250
|
+
|
|
251
|
+
The builder refuses with `EnginiBuilderError` (`code`, `path`, `fix`, `diagnostics`,
|
|
252
|
+
`currentRevisionId`; extends `EnginiAPIError`). Branch on `code`, not on the status class:
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
try {
|
|
256
|
+
await client.workflows.update(id, { plan, expectedRevisionId });
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (err instanceof EnginiBuilderError && err.code === "REVISION_CONFLICT") {
|
|
259
|
+
// re-read with getPlan(id), merge, retry against err.currentRevisionId
|
|
260
|
+
} else if (err instanceof EnginiBuilderError && err.code === "PLAN_HAS_ERRORS") {
|
|
261
|
+
console.error(err.diagnostics); // [{ severity, code, stepKey, field, message }]
|
|
262
|
+
} else throw err;
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
201
266
|
## Files
|
|
202
267
|
|
|
203
268
|
Tools whose `inputSchema` marks a field `"format": "engini/file"` accept files. Wrap a file with
|
package/dist/client.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ import { McpResource } from "./resources/mcp.js";
|
|
|
8
8
|
import { AuthProvidersResource } from "./resources/authProviders.js";
|
|
9
9
|
import { OpaResource } from "./resources/opa.js";
|
|
10
10
|
import { TriggersResource } from "./resources/triggers.js";
|
|
11
|
+
import { ExecutionsResource } from "./resources/executions.js";
|
|
12
|
+
import { FoldersResource } from "./resources/folders.js";
|
|
13
|
+
import { WorkflowsResource } from "./resources/workflows.js";
|
|
11
14
|
import { ApplicationsResource } from "./resources/applications.js";
|
|
12
15
|
import { AuthResource } from "./resources/auth.js";
|
|
13
16
|
import { Toolset, type ConnectionBinding } from "./toolset.js";
|
|
@@ -55,6 +58,9 @@ export declare class Engini {
|
|
|
55
58
|
readonly opa: OpaResource;
|
|
56
59
|
readonly authProviders: AuthProvidersResource;
|
|
57
60
|
readonly triggers: TriggersResource;
|
|
61
|
+
readonly executions: ExecutionsResource;
|
|
62
|
+
readonly workflows: WorkflowsResource;
|
|
63
|
+
readonly folders: FoldersResource;
|
|
58
64
|
readonly applications: ApplicationsResource;
|
|
59
65
|
readonly auth: AuthResource;
|
|
60
66
|
readonly provider: Provider;
|
package/dist/client.js
CHANGED
|
@@ -9,6 +9,9 @@ import { McpResource } from "./resources/mcp.js";
|
|
|
9
9
|
import { AuthProvidersResource } from "./resources/authProviders.js";
|
|
10
10
|
import { OpaResource } from "./resources/opa.js";
|
|
11
11
|
import { TriggersResource } from "./resources/triggers.js";
|
|
12
|
+
import { ExecutionsResource } from "./resources/executions.js";
|
|
13
|
+
import { FoldersResource } from "./resources/folders.js";
|
|
14
|
+
import { WorkflowsResource } from "./resources/workflows.js";
|
|
12
15
|
import { ApplicationsResource } from "./resources/applications.js";
|
|
13
16
|
import { AuthResource } from "./resources/auth.js";
|
|
14
17
|
import { Toolset } from "./toolset.js";
|
|
@@ -22,6 +25,9 @@ export class Engini {
|
|
|
22
25
|
opa;
|
|
23
26
|
authProviders;
|
|
24
27
|
triggers;
|
|
28
|
+
executions;
|
|
29
|
+
workflows;
|
|
30
|
+
folders;
|
|
25
31
|
applications;
|
|
26
32
|
auth;
|
|
27
33
|
provider;
|
|
@@ -78,6 +84,9 @@ export class Engini {
|
|
|
78
84
|
this.opa = new OpaResource(this);
|
|
79
85
|
this.authProviders = new AuthProvidersResource(this);
|
|
80
86
|
this.triggers = new TriggersResource(this);
|
|
87
|
+
this.executions = new ExecutionsResource(this);
|
|
88
|
+
this.workflows = new WorkflowsResource(this);
|
|
89
|
+
this.folders = new FoldersResource(this);
|
|
81
90
|
this.applications = new ApplicationsResource(this);
|
|
82
91
|
this.auth = new AuthResource(this);
|
|
83
92
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -53,6 +53,44 @@ export declare class EnginiConflictError extends EnginiAPIError {
|
|
|
53
53
|
/** 5xx — the API failed internally. */
|
|
54
54
|
export declare class EnginiServerError extends EnginiAPIError {
|
|
55
55
|
}
|
|
56
|
+
/** One diagnostic of a refused plan (wire `BuilderDiagnostic`). */
|
|
57
|
+
export interface BuilderDiagnostic {
|
|
58
|
+
severity: string;
|
|
59
|
+
code: string;
|
|
60
|
+
stepKey?: string | null;
|
|
61
|
+
field?: string | null;
|
|
62
|
+
message: string;
|
|
63
|
+
}
|
|
64
|
+
export interface EnginiBuilderErrorOptions extends EnginiAPIErrorOptions {
|
|
65
|
+
status?: number;
|
|
66
|
+
path?: string | null;
|
|
67
|
+
fix?: string | null;
|
|
68
|
+
diagnostics?: BuilderDiagnostic[];
|
|
69
|
+
currentRevisionId?: number | null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The workflow builder's `application/problem+json` refusal (`/v1/workflows*`).
|
|
73
|
+
*
|
|
74
|
+
* Mapped from the *body* — a string `code` member — not the status, because the builder
|
|
75
|
+
* answers 400/404/409/422/500/502 in one shape and only `code` (`PLAN_HAS_ERRORS`,
|
|
76
|
+
* `REVISION_CONFLICT`, `WORKFLOW_ACTIVE`, `SCOPE_REQUIRED`, …) says what happened.
|
|
77
|
+
* It extends `EnginiAPIError` rather than the status-class errors, so `instanceof
|
|
78
|
+
* EnginiConflictError` does not match a 409 here; branch on `code`.
|
|
79
|
+
*
|
|
80
|
+
* `errorCode` mirrors `code` so code reading the base field keeps working. `diagnostics`
|
|
81
|
+
* is filled with `PLAN_HAS_ERRORS`; `currentRevisionId` with `REVISION_CONFLICT`.
|
|
82
|
+
*/
|
|
83
|
+
export declare class EnginiBuilderError extends EnginiAPIError {
|
|
84
|
+
readonly status: number | undefined;
|
|
85
|
+
readonly code: string;
|
|
86
|
+
readonly path: string | null;
|
|
87
|
+
readonly fix: string | null;
|
|
88
|
+
readonly diagnostics: BuilderDiagnostic[];
|
|
89
|
+
readonly currentRevisionId: number | null;
|
|
90
|
+
constructor(message: string, options: EnginiBuilderErrorOptions & {
|
|
91
|
+
code: string;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
56
94
|
/** SDK misuse (e.g., a provider used without its optional peer installed). */
|
|
57
95
|
export declare class EnginiClientError extends EnginiError {
|
|
58
96
|
}
|
package/dist/errors.js
CHANGED
|
@@ -40,6 +40,39 @@ export class EnginiConflictError extends EnginiAPIError {
|
|
|
40
40
|
/** 5xx — the API failed internally. */
|
|
41
41
|
export class EnginiServerError extends EnginiAPIError {
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The workflow builder's `application/problem+json` refusal (`/v1/workflows*`).
|
|
45
|
+
*
|
|
46
|
+
* Mapped from the *body* — a string `code` member — not the status, because the builder
|
|
47
|
+
* answers 400/404/409/422/500/502 in one shape and only `code` (`PLAN_HAS_ERRORS`,
|
|
48
|
+
* `REVISION_CONFLICT`, `WORKFLOW_ACTIVE`, `SCOPE_REQUIRED`, …) says what happened.
|
|
49
|
+
* It extends `EnginiAPIError` rather than the status-class errors, so `instanceof
|
|
50
|
+
* EnginiConflictError` does not match a 409 here; branch on `code`.
|
|
51
|
+
*
|
|
52
|
+
* `errorCode` mirrors `code` so code reading the base field keeps working. `diagnostics`
|
|
53
|
+
* is filled with `PLAN_HAS_ERRORS`; `currentRevisionId` with `REVISION_CONFLICT`.
|
|
54
|
+
*/
|
|
55
|
+
export class EnginiBuilderError extends EnginiAPIError {
|
|
56
|
+
status;
|
|
57
|
+
code;
|
|
58
|
+
path;
|
|
59
|
+
fix;
|
|
60
|
+
diagnostics;
|
|
61
|
+
currentRevisionId;
|
|
62
|
+
constructor(message, options) {
|
|
63
|
+
super(message, {
|
|
64
|
+
errorCode: options.code,
|
|
65
|
+
details: options.diagnostics ?? [],
|
|
66
|
+
retryAfter: options.retryAfter,
|
|
67
|
+
});
|
|
68
|
+
this.status = options.status;
|
|
69
|
+
this.code = options.code;
|
|
70
|
+
this.path = options.path ?? null;
|
|
71
|
+
this.fix = options.fix ?? null;
|
|
72
|
+
this.diagnostics = options.diagnostics ?? [];
|
|
73
|
+
this.currentRevisionId = options.currentRevisionId ?? null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
43
76
|
/** SDK misuse (e.g., a provider used without its optional peer installed). */
|
|
44
77
|
export class EnginiClientError extends EnginiError {
|
|
45
78
|
}
|
package/dist/http.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { Agent } from "undici";
|
|
9
9
|
import { createEnginiClient } from "@engini/client";
|
|
10
|
-
import { EnginiAPIError, EnginiAuthError, EnginiClientError, EnginiConflictError, EnginiNetworkError, EnginiNotFoundError, EnginiRateLimitError, EnginiServerError, EnginiValidationError, } from "./errors.js";
|
|
10
|
+
import { EnginiAPIError, EnginiAuthError, EnginiBuilderError, EnginiClientError, EnginiConflictError, EnginiNetworkError, EnginiNotFoundError, EnginiRateLimitError, EnginiServerError, EnginiValidationError, } from "./errors.js";
|
|
11
11
|
import { VERSION } from "./version.js";
|
|
12
12
|
/**
|
|
13
13
|
* Map a `verify` setting onto an undici `Dispatcher`, or `undefined` to keep the
|
|
@@ -132,6 +132,22 @@ export function parseRetryAfter(value) {
|
|
|
132
132
|
*/
|
|
133
133
|
export function errorForStatus(status, error, headers) {
|
|
134
134
|
const message = errorMessage(error, status);
|
|
135
|
+
// The builder's problem+json has `code` (the generic ErrorResponse has `errorCode`).
|
|
136
|
+
const problem = error;
|
|
137
|
+
if (problem && typeof problem === "object" && typeof problem.code === "string") {
|
|
138
|
+
const m = error.message;
|
|
139
|
+
return new EnginiBuilderError(typeof m === "string" ? `${problem.code}: ${m}` : problem.code, {
|
|
140
|
+
code: problem.code,
|
|
141
|
+
status,
|
|
142
|
+
path: typeof problem.path === "string" ? problem.path : null,
|
|
143
|
+
fix: typeof problem.fix === "string" ? problem.fix : null,
|
|
144
|
+
diagnostics: Array.isArray(problem.diagnostics)
|
|
145
|
+
? problem.diagnostics
|
|
146
|
+
: [],
|
|
147
|
+
currentRevisionId: typeof problem.currentRevisionId === "number" ? problem.currentRevisionId : null,
|
|
148
|
+
retryAfter: parseRetryAfter(headers?.get("retry-after")),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
135
151
|
const Ctor = STATUS_TO_ERROR[status] ?? (status >= 500 ? EnginiServerError : EnginiAPIError);
|
|
136
152
|
// Carry the parsed body, not just its rendered message: callers need to tell
|
|
137
153
|
// apart conditions that share a status, and `details` is the only channel for
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ export type { Auth } from "./auth.js";
|
|
|
5
5
|
export { composeUserAgent } from "./http.js";
|
|
6
6
|
export type { Verify } from "./http.js";
|
|
7
7
|
export { VERSION } from "./version.js";
|
|
8
|
-
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaApplicationAmbiguousError, EnginiOpaAgentTimeoutError, EnginiOpaAgentDispatchError, EnginiTriggerGapError, EnginiTriggerSubscribeFailedError, EnginiTriggerStreamLimitError, EnginiWebhookSignatureError, } from "./errors.js";
|
|
9
|
-
export type { EnginiAPIErrorOptions } from "./errors.js";
|
|
10
|
-
export {
|
|
11
|
-
export type {
|
|
8
|
+
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaApplicationAmbiguousError, EnginiOpaAgentTimeoutError, EnginiOpaAgentDispatchError, EnginiTriggerGapError, EnginiTriggerSubscribeFailedError, EnginiTriggerStreamLimitError, EnginiWebhookSignatureError, EnginiBuilderError, } from "./errors.js";
|
|
9
|
+
export type { EnginiAPIErrorOptions, EnginiBuilderErrorOptions, BuilderDiagnostic, } from "./errors.js";
|
|
10
|
+
export { paginateCursor } from "./pagination.js";
|
|
11
|
+
export type { CursorPage } from "./pagination.js";
|
|
12
|
+
export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, OpaResource, AuthProvidersResource, TriggersResource, ApplicationsResource, ExecutionsResource, WorkflowsResource, FoldersResource, refreshFailed, verifyWebhook, } from "./resources/index.js";
|
|
13
|
+
export type { ToolsGetOptions, ToolsExecuteOptions, ApplicationsListOptions, TriggersClient, TriggerWebhookEvent, ExecutionsClient, ExecutionsListParams, WorkflowsClient, WorkflowsListParams, FoldersClient, FoldersListParams, } from "./resources/index.js";
|
|
12
14
|
export { Toolset } from "./toolset.js";
|
|
13
15
|
export type { ConnectionBinding, ToolsetExecuteOptions } from "./toolset.js";
|
|
14
16
|
export { File } from "./files.js";
|
|
@@ -18,6 +20,7 @@ export type { ToolsetConnectionDto, ToolsetConnectionRequest, ToolsetDto } from
|
|
|
18
20
|
export type { AuthProviderResponse, AuthProviderFieldValue, AuthProviderFieldDefinition, AuthProviderSourceApplication, AuthProviderSourceMethod, AuthProviderRedirectUriResponse, CreateAuthProviderRequest, UpdateAuthProviderRequest, UsableAuthProvider, } from "@engini/client";
|
|
19
21
|
export type { OnPremAgentListItem as OpaAgentListItem, OnPremAgentDetail as OpaAgentDetail, OnPremAgentSettings as OpaAgentSettings, OnPremAgentTokenResponse as OpaAgentTokenResponse, OnPremAgentCreateResponse as OpaAgentCreateResponse, OnPremAgentReleaseManifest as OpaReleaseManifest, CreateOnPremAgentRequest as CreateOpaAgentRequest, UpdateOnPremAgentRequest as UpdateOpaAgentRequest, } from "@engini/client";
|
|
20
22
|
export type { TriggerTypeDto, TriggerTypeDetailDto, TriggerParametersDto, TriggerInstanceView, TriggerInstanceStatus, TriggerKind, TriggerStatusReason, TriggerScheduleDto, TriggerScheduleFrequency, TriggerTimeFrameDto, TriggerEventView, TriggerEventDetailView, TriggerEventDeliveryStateDto, TriggerDeliveryAttemptView, TriggerDestinationView, TriggerDestinationCreated, TriggerDestinationStatusDto, CreateTriggerRequest, PatchTriggerRequest, CreateTriggerDestinationRequest, PatchTriggerDestinationRequest, PutDefaultDestinationRequest, } from "@engini/client";
|
|
23
|
+
export type { ExecutionPublicDto, ExecutionLogEntryPublicDto, ExecutionDataEntryPublicDto, ExecutionLoopPublicDto, CursorPaginatedResponseOfExecutionPublicDto, CatalogHit, OptionItem, TableItem, TableColumn, BuilderConnectionInfo, BuilderProblem, CompiledWorkflowDto, CompileRequest, CreateFromPlanRequest, CreateFromPlanResponse, UpdateFromPlanRequest, UpdateFromPlanResponse, WorkflowPlan, PlanStep, } from "@engini/client";
|
|
21
24
|
export type { McpServerPublicDto, McpServerConnectionDto, McpServerConnectionRequest, McpServerWorkflowDto, McpServerWorkflowRequest, McpAvailableToolDto, } from "@engini/client";
|
|
22
25
|
export type { Provider, ToolCall, ToolResultOptions } from "./providers/base.js";
|
|
23
26
|
export { OpenAIProvider } from "./providers/openai.js";
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,9 @@ export { Engini, DEFAULT_BASE_URL } from "./client.js";
|
|
|
2
2
|
export { ApiKeyAuth, BearerAuth, ENV_API_KEY_VAR, ENV_TOKEN_VAR, ENV_COMPANY_TOKEN_VAR, } from "./auth.js";
|
|
3
3
|
export { composeUserAgent } from "./http.js";
|
|
4
4
|
export { VERSION } from "./version.js";
|
|
5
|
-
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaApplicationAmbiguousError, EnginiOpaAgentTimeoutError, EnginiOpaAgentDispatchError, EnginiTriggerGapError, EnginiTriggerSubscribeFailedError, EnginiTriggerStreamLimitError, EnginiWebhookSignatureError, } from "./errors.js";
|
|
6
|
-
export {
|
|
5
|
+
export { EnginiError, EnginiNetworkError, EnginiAPIError, EnginiAuthError, EnginiNotFoundError, EnginiValidationError, EnginiRateLimitError, EnginiConflictError, EnginiServerError, EnginiClientError, EnginiConnectionError, EnginiToolsetError, EnginiToolsetNotFoundError, EnginiMcpServerNotFoundError, EnginiTimeoutError, EnginiToolExecutionError, EnginiOpaAgentNotFoundError, EnginiOpaAgentOfflineError, EnginiOpaApplicationAmbiguousError, EnginiOpaAgentTimeoutError, EnginiOpaAgentDispatchError, EnginiTriggerGapError, EnginiTriggerSubscribeFailedError, EnginiTriggerStreamLimitError, EnginiWebhookSignatureError, EnginiBuilderError, } from "./errors.js";
|
|
6
|
+
export { paginateCursor } from "./pagination.js";
|
|
7
|
+
export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, OpaResource, AuthProvidersResource, TriggersResource, ApplicationsResource, ExecutionsResource, WorkflowsResource, FoldersResource, refreshFailed, verifyWebhook, } from "./resources/index.js";
|
|
7
8
|
export { Toolset } from "./toolset.js";
|
|
8
9
|
export { File } from "./files.js";
|
|
9
10
|
export { OpenAIProvider } from "./providers/openai.js";
|
package/dist/pagination.d.ts
CHANGED
|
@@ -15,3 +15,18 @@ export declare function paginate<T>(fetchPage: (offset: number, top: number) =>
|
|
|
15
15
|
}): AsyncGenerator<T>;
|
|
16
16
|
/** Collect an async generator into an array (convenience for resources). */
|
|
17
17
|
export declare function collect<T>(gen: AsyncIterable<T>): Promise<T[]>;
|
|
18
|
+
/** The shape of a `CursorPaginatedResponseOf*` envelope: pages chain through `nextCursor`. */
|
|
19
|
+
export interface CursorPage<T> {
|
|
20
|
+
items: T[];
|
|
21
|
+
nextCursor?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Auto-pagination over a cursor envelope. `fetchPage(cursor, top)` gets `undefined`
|
|
25
|
+
* for the first page, then each page's `nextCursor`, until it is absent.
|
|
26
|
+
*
|
|
27
|
+
* Stops early on an empty page or a cursor that repeats: a server that handed back the
|
|
28
|
+
* cursor it was just given would otherwise loop for ever.
|
|
29
|
+
*/
|
|
30
|
+
export declare function paginateCursor<T>(fetchPage: (cursor: string | undefined, top: number) => Promise<CursorPage<T>>, options?: {
|
|
31
|
+
top?: number;
|
|
32
|
+
}): AsyncGenerator<T>;
|
package/dist/pagination.js
CHANGED
|
@@ -23,3 +23,25 @@ export async function collect(gen) {
|
|
|
23
23
|
out.push(item);
|
|
24
24
|
return out;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Auto-pagination over a cursor envelope. `fetchPage(cursor, top)` gets `undefined`
|
|
28
|
+
* for the first page, then each page's `nextCursor`, until it is absent.
|
|
29
|
+
*
|
|
30
|
+
* Stops early on an empty page or a cursor that repeats: a server that handed back the
|
|
31
|
+
* cursor it was just given would otherwise loop for ever.
|
|
32
|
+
*/
|
|
33
|
+
export async function* paginateCursor(fetchPage, options = {}) {
|
|
34
|
+
const top = options.top ?? 100;
|
|
35
|
+
let cursor;
|
|
36
|
+
while (true) {
|
|
37
|
+
const page = await fetchPage(cursor, top);
|
|
38
|
+
const items = page.items ?? [];
|
|
39
|
+
for (const item of items)
|
|
40
|
+
yield item;
|
|
41
|
+
const next = page.nextCursor;
|
|
42
|
+
if (items.length === 0 || next === undefined || next === null || next === "" || next === cursor) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
cursor = next;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -27,9 +27,12 @@ export declare class AuthProvidersResource {
|
|
|
27
27
|
get(id: number): Promise<AuthProviderResponse>;
|
|
28
28
|
/**
|
|
29
29
|
* Create a provider. `fieldValues` is keyed by slot; password values are write-only. A body
|
|
30
|
-
* carrying `clientId` / `clientSecret` is a 400 `INVALID_AUTH_PROVIDER`.
|
|
30
|
+
* carrying `clientId` / `clientSecret` is a 400 `INVALID_AUTH_PROVIDER`. `allowScopeExtend`
|
|
31
|
+
* is required by engini-client 0.18.0's type; here it defaults to `true`, the server's default.
|
|
31
32
|
*/
|
|
32
|
-
create(body: CreateAuthProviderRequest
|
|
33
|
+
create(body: Omit<CreateAuthProviderRequest, "allowScopeExtend"> & {
|
|
34
|
+
allowScopeExtend?: boolean;
|
|
35
|
+
}): Promise<AuthProviderResponse>;
|
|
33
36
|
/**
|
|
34
37
|
* Partial update: an omitted field is left alone. In `fieldValues`, an omitted slot keeps its
|
|
35
38
|
* stored value and `""` clears it.
|
|
@@ -29,10 +29,14 @@ export class AuthProvidersResource {
|
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Create a provider. `fieldValues` is keyed by slot; password values are write-only. A body
|
|
32
|
-
* carrying `clientId` / `clientSecret` is a 400 `INVALID_AUTH_PROVIDER`.
|
|
32
|
+
* carrying `clientId` / `clientSecret` is a 400 `INVALID_AUTH_PROVIDER`. `allowScopeExtend`
|
|
33
|
+
* is required by engini-client 0.18.0's type; here it defaults to `true`, the server's default.
|
|
33
34
|
*/
|
|
34
35
|
async create(body) {
|
|
35
|
-
return call(authProvidersCreate, {
|
|
36
|
+
return call(authProvidersCreate, {
|
|
37
|
+
client: this.client._transport,
|
|
38
|
+
body: { allowScopeExtend: true, ...body },
|
|
39
|
+
});
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Partial update: an omitted field is left alone. In `fieldValues`, an omitted slot keeps its
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executions resource — read-only history of workflow, table-automation and
|
|
3
|
+
* business-rule runs (`/v1/executions*`). There is no rerun on this surface.
|
|
4
|
+
*/
|
|
5
|
+
import { type ExecutionDataEntryPublicDto, type ExecutionLogEntryPublicDto, type ExecutionPublicDto, type ExecutionsListExecutionsData } from "@engini/client";
|
|
6
|
+
import { type Transport } from "../http.js";
|
|
7
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
8
|
+
export interface ExecutionsClient {
|
|
9
|
+
_transport: Transport;
|
|
10
|
+
}
|
|
11
|
+
type ListQuery = NonNullable<ExecutionsListExecutionsData["query"]>;
|
|
12
|
+
/** Filters for `executions.list`; `top`/`cursor`/`offset` are handled by the method. */
|
|
13
|
+
export type ExecutionsListParams = Omit<ListQuery, "top" | "cursor" | "offset"> & {
|
|
14
|
+
/**
|
|
15
|
+
* With `top`, fetch one page of at most `top` rows (server cap 100) instead of
|
|
16
|
+
* draining. `cursor` / `offset` are only meaningful together with `top`.
|
|
17
|
+
*/
|
|
18
|
+
top?: number;
|
|
19
|
+
/** A previous page's `nextCursor`. Not available when sorting by `closedAt`. */
|
|
20
|
+
cursor?: string;
|
|
21
|
+
offset?: number;
|
|
22
|
+
};
|
|
23
|
+
export declare class ExecutionsResource {
|
|
24
|
+
private readonly client;
|
|
25
|
+
constructor(client: ExecutionsClient);
|
|
26
|
+
/**
|
|
27
|
+
* Executions, newest first by default.
|
|
28
|
+
*
|
|
29
|
+
* With no `top`, drains every match: it follows `nextCursor` until the server omits it,
|
|
30
|
+
* 100 per page. Sorting by `closedAt` or by several keys has no cursor on the server,
|
|
31
|
+
* so that case drains by `offset` instead: rows that arrive mid-drain shift the pages, so it
|
|
32
|
+
* de-dupes by `executionId` but can still skip a row - re-run for a stable window (e.g. with
|
|
33
|
+
* `createdBefore`). Pass `top` for one bounded page — add `cursor`
|
|
34
|
+
* (a previous page's `nextCursor`) or `offset` to read a later one; use `listPage` to
|
|
35
|
+
* get `nextCursor` back.
|
|
36
|
+
*/
|
|
37
|
+
list(params?: ExecutionsListParams): Promise<ExecutionPublicDto[]>;
|
|
38
|
+
/** One page, with its `nextCursor` and `totalCount`. */
|
|
39
|
+
listPage(params?: ExecutionsListParams): Promise<import("@engini/client").CursorPaginatedResponseOfExecutionPublicDto>;
|
|
40
|
+
/** One execution. */
|
|
41
|
+
get(executionId: number): Promise<ExecutionPublicDto>;
|
|
42
|
+
/**
|
|
43
|
+
* The execution's per-step log. A 410 (retention window passed) throws
|
|
44
|
+
* `EnginiAPIError` — the execution itself is still listed.
|
|
45
|
+
*/
|
|
46
|
+
log(executionId: number): Promise<ExecutionLogEntryPublicDto[]>;
|
|
47
|
+
/**
|
|
48
|
+
* The request/response/input/status payloads recorded for one step.
|
|
49
|
+
*
|
|
50
|
+
* With no `top`, drains by `offset`; the server returns at most 10 per page. Pass `top`
|
|
51
|
+
* for a single page (`offset` is only valid with `top`).
|
|
52
|
+
*/
|
|
53
|
+
data(executionId: number, stepNo: number, params?: {
|
|
54
|
+
type?: string;
|
|
55
|
+
loopPath?: string[];
|
|
56
|
+
runNumber?: number;
|
|
57
|
+
retryNo?: number;
|
|
58
|
+
status?: string;
|
|
59
|
+
top?: number;
|
|
60
|
+
offset?: number;
|
|
61
|
+
}): Promise<ExecutionDataEntryPublicDto[]>;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executions resource — read-only history of workflow, table-automation and
|
|
3
|
+
* business-rule runs (`/v1/executions*`). There is no rerun on this surface.
|
|
4
|
+
*/
|
|
5
|
+
import { executionsGetExecution, executionsGetExecutionLog, executionsListExecutionData, executionsListExecutions, } from "@engini/client";
|
|
6
|
+
import { EnginiClientError } from "../errors.js";
|
|
7
|
+
import { call } from "../http.js";
|
|
8
|
+
import { collect, paginate, paginateCursor } from "../pagination.js";
|
|
9
|
+
/** Cursor paging only works for a single createdAt / executionId key. */
|
|
10
|
+
function supportsCursor(sort) {
|
|
11
|
+
if (sort === undefined || sort === null || sort.trim() === "")
|
|
12
|
+
return true;
|
|
13
|
+
return !sort.includes(",") && !/closedat/i.test(sort);
|
|
14
|
+
}
|
|
15
|
+
export class ExecutionsResource {
|
|
16
|
+
client;
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Executions, newest first by default.
|
|
22
|
+
*
|
|
23
|
+
* With no `top`, drains every match: it follows `nextCursor` until the server omits it,
|
|
24
|
+
* 100 per page. Sorting by `closedAt` or by several keys has no cursor on the server,
|
|
25
|
+
* so that case drains by `offset` instead: rows that arrive mid-drain shift the pages, so it
|
|
26
|
+
* de-dupes by `executionId` but can still skip a row - re-run for a stable window (e.g. with
|
|
27
|
+
* `createdBefore`). Pass `top` for one bounded page — add `cursor`
|
|
28
|
+
* (a previous page's `nextCursor`) or `offset` to read a later one; use `listPage` to
|
|
29
|
+
* get `nextCursor` back.
|
|
30
|
+
*/
|
|
31
|
+
async list(params = {}) {
|
|
32
|
+
const { top, cursor, offset, ...filters } = params;
|
|
33
|
+
if (top !== undefined) {
|
|
34
|
+
return (await this.listPage({ ...filters, top, cursor, offset })).items ?? [];
|
|
35
|
+
}
|
|
36
|
+
if (offset !== undefined || cursor !== undefined) {
|
|
37
|
+
throw new EnginiClientError("`offset` / `cursor` need `top`; without `top` every page is drained from the start.");
|
|
38
|
+
}
|
|
39
|
+
const transport = this.client._transport;
|
|
40
|
+
if (supportsCursor(filters.sort)) {
|
|
41
|
+
return collect(paginateCursor(async (next, pageSize) => call(executionsListExecutions, {
|
|
42
|
+
client: transport,
|
|
43
|
+
query: { ...filters, top: pageSize, cursor: next },
|
|
44
|
+
})));
|
|
45
|
+
}
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
const rows = await collect(paginate(async (skip, pageSize) => {
|
|
48
|
+
const page = await call(executionsListExecutions, {
|
|
49
|
+
client: transport,
|
|
50
|
+
query: { ...filters, top: pageSize, offset: skip },
|
|
51
|
+
});
|
|
52
|
+
return { ...page, totalCount: page.totalCount ?? 0 };
|
|
53
|
+
}));
|
|
54
|
+
return rows.filter((row) => !seen.has(row.executionId) && seen.add(row.executionId));
|
|
55
|
+
}
|
|
56
|
+
/** One page, with its `nextCursor` and `totalCount`. */
|
|
57
|
+
async listPage(params = {}) {
|
|
58
|
+
return call(executionsListExecutions, {
|
|
59
|
+
client: this.client._transport,
|
|
60
|
+
query: params,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** One execution. */
|
|
64
|
+
async get(executionId) {
|
|
65
|
+
return call(executionsGetExecution, {
|
|
66
|
+
client: this.client._transport,
|
|
67
|
+
path: { executionId },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The execution's per-step log. A 410 (retention window passed) throws
|
|
72
|
+
* `EnginiAPIError` — the execution itself is still listed.
|
|
73
|
+
*/
|
|
74
|
+
async log(executionId) {
|
|
75
|
+
return call(executionsGetExecutionLog, {
|
|
76
|
+
client: this.client._transport,
|
|
77
|
+
path: { executionId },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The request/response/input/status payloads recorded for one step.
|
|
82
|
+
*
|
|
83
|
+
* With no `top`, drains by `offset`; the server returns at most 10 per page. Pass `top`
|
|
84
|
+
* for a single page (`offset` is only valid with `top`).
|
|
85
|
+
*/
|
|
86
|
+
async data(executionId, stepNo, params = {}) {
|
|
87
|
+
const transport = this.client._transport;
|
|
88
|
+
const { top, offset, ...filters } = params;
|
|
89
|
+
const fetchPage = (skip, pageSize) => call(executionsListExecutionData, {
|
|
90
|
+
client: transport,
|
|
91
|
+
path: { executionId, stepNo },
|
|
92
|
+
query: { ...filters, offset: skip, top: pageSize },
|
|
93
|
+
});
|
|
94
|
+
if (top !== undefined)
|
|
95
|
+
return (await fetchPage(offset ?? 0, top)).items ?? [];
|
|
96
|
+
if (offset !== undefined) {
|
|
97
|
+
throw new EnginiClientError("`offset` needs `top`; without `top` every page is drained from the start.");
|
|
98
|
+
}
|
|
99
|
+
return collect(paginate(fetchPage, { top: 10 }));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folders resource — the folders that organize workflows in each workspace and environment
|
|
3
|
+
* (`GET /v1/folders`). Use it to turn a folder name into the `folderId` that
|
|
4
|
+
* `workflows.list` and `workflows.create` take.
|
|
5
|
+
*/
|
|
6
|
+
import { type FolderPublicDto, type FoldersListFoldersData } from "@engini/client";
|
|
7
|
+
import { type Transport } from "../http.js";
|
|
8
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
9
|
+
export interface FoldersClient {
|
|
10
|
+
_transport: Transport;
|
|
11
|
+
}
|
|
12
|
+
type ListQuery = NonNullable<FoldersListFoldersData["query"]>;
|
|
13
|
+
/**
|
|
14
|
+
* Filters for `folders.list`. `type` is not offered: this resource lists workflow folders only
|
|
15
|
+
* (the only kind the server serves; table folders answer 501), so it always sends `type=workflow`.
|
|
16
|
+
*/
|
|
17
|
+
export type FoldersListParams = Omit<ListQuery, "type" | "top" | "offset"> & {
|
|
18
|
+
/** With `top`, fetch one page of at most `top` rows (server cap 100) instead of draining. */
|
|
19
|
+
top?: number;
|
|
20
|
+
/** Only meaningful together with `top`. */
|
|
21
|
+
offset?: number;
|
|
22
|
+
};
|
|
23
|
+
export declare class FoldersResource {
|
|
24
|
+
private readonly client;
|
|
25
|
+
constructor(client: FoldersClient);
|
|
26
|
+
/**
|
|
27
|
+
* Workflow folders, by name unless `sort` says otherwise. `name` is a case-insensitive
|
|
28
|
+
* substring match, so several folders can match: compare `name` yourself for an exact one.
|
|
29
|
+
*
|
|
30
|
+
* With no `top`, drains every match by `offset`, 100 per page. Pass `top` for one bounded page
|
|
31
|
+
* (add `offset` to read a later one); use `listPage` to get `totalCount` back.
|
|
32
|
+
* A row deleted mid-drain can still be skipped.
|
|
33
|
+
*/
|
|
34
|
+
list(params?: FoldersListParams): Promise<FolderPublicDto[]>;
|
|
35
|
+
/** One page, with its `totalCount`. */
|
|
36
|
+
listPage(params?: FoldersListParams): Promise<import("@engini/client").PaginatedResponseOfFolderPublicDto>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folders resource — the folders that organize workflows in each workspace and environment
|
|
3
|
+
* (`GET /v1/folders`). Use it to turn a folder name into the `folderId` that
|
|
4
|
+
* `workflows.list` and `workflows.create` take.
|
|
5
|
+
*/
|
|
6
|
+
import { foldersListFolders } from "@engini/client";
|
|
7
|
+
import { EnginiClientError } from "../errors.js";
|
|
8
|
+
import { call } from "../http.js";
|
|
9
|
+
import { collect, paginate } from "../pagination.js";
|
|
10
|
+
export class FoldersResource {
|
|
11
|
+
client;
|
|
12
|
+
constructor(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Workflow folders, by name unless `sort` says otherwise. `name` is a case-insensitive
|
|
17
|
+
* substring match, so several folders can match: compare `name` yourself for an exact one.
|
|
18
|
+
*
|
|
19
|
+
* With no `top`, drains every match by `offset`, 100 per page. Pass `top` for one bounded page
|
|
20
|
+
* (add `offset` to read a later one); use `listPage` to get `totalCount` back.
|
|
21
|
+
* A row deleted mid-drain can still be skipped.
|
|
22
|
+
*/
|
|
23
|
+
async list(params = {}) {
|
|
24
|
+
const { top, offset, ...filters } = params;
|
|
25
|
+
if (top !== undefined)
|
|
26
|
+
return (await this.listPage({ ...filters, top, offset })).items ?? [];
|
|
27
|
+
if (offset !== undefined) {
|
|
28
|
+
throw new EnginiClientError("`offset` needs `top`; without `top` every page is drained from the start.");
|
|
29
|
+
}
|
|
30
|
+
const rows = await collect(paginate((skip, pageSize) => call(foldersListFolders, {
|
|
31
|
+
client: this.client._transport,
|
|
32
|
+
query: { ...filters, type: "workflow", offset: skip, top: pageSize },
|
|
33
|
+
})));
|
|
34
|
+
// A folder created mid-drain shifts later pages and repeats a row: keep the first (rows without an id all stay).
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
return rows.filter((row) => row.id == null || (!seen.has(row.id) && !!seen.add(row.id)));
|
|
37
|
+
}
|
|
38
|
+
/** One page, with its `totalCount`. */
|
|
39
|
+
async listPage(params = {}) {
|
|
40
|
+
return call(foldersListFolders, {
|
|
41
|
+
client: this.client._transport,
|
|
42
|
+
query: { ...params, type: "workflow" },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -9,5 +9,11 @@ export { OpaResource } from "./opa.js";
|
|
|
9
9
|
export type { OpaClient } from "./opa.js";
|
|
10
10
|
export { TriggersResource, verifyWebhook } from "./triggers.js";
|
|
11
11
|
export type { TriggersClient, TriggerWebhookEvent } from "./triggers.js";
|
|
12
|
+
export { ExecutionsResource } from "./executions.js";
|
|
13
|
+
export type { ExecutionsClient, ExecutionsListParams } from "./executions.js";
|
|
14
|
+
export { WorkflowsResource } from "./workflows.js";
|
|
15
|
+
export type { WorkflowsClient, WorkflowsListParams } from "./workflows.js";
|
|
16
|
+
export { FoldersResource } from "./folders.js";
|
|
17
|
+
export type { FoldersClient, FoldersListParams } from "./folders.js";
|
|
12
18
|
export { ApplicationsResource } from "./applications.js";
|
|
13
19
|
export type { ApplicationsListOptions } from "./applications.js";
|
package/dist/resources/index.js
CHANGED
|
@@ -5,4 +5,7 @@ export { McpResource } from "./mcp.js";
|
|
|
5
5
|
export { AuthProvidersResource } from "./authProviders.js";
|
|
6
6
|
export { OpaResource } from "./opa.js";
|
|
7
7
|
export { TriggersResource, verifyWebhook } from "./triggers.js";
|
|
8
|
+
export { ExecutionsResource } from "./executions.js";
|
|
9
|
+
export { WorkflowsResource } from "./workflows.js";
|
|
10
|
+
export { FoldersResource } from "./folders.js";
|
|
8
11
|
export { ApplicationsResource } from "./applications.js";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflows resource — list workflows (`GET /v1/workflows`) and the workflow builder
|
|
3
|
+
* (`/v1/workflows*`): look up what a plan may use
|
|
4
|
+
* (catalog, schemas, options, tables, connections), dry-run a plan with `compile`, and write
|
|
5
|
+
* one with `create` / `update`.
|
|
6
|
+
*
|
|
7
|
+
* Refusals arrive as `EnginiBuilderError` (`code`, `path`, `fix`, `diagnostics`,
|
|
8
|
+
* `currentRevisionId`). Writes need a workspace-scoped API key (`SCOPE_REQUIRED` otherwise),
|
|
9
|
+
* and a workflow is always created turned off.
|
|
10
|
+
*/
|
|
11
|
+
import { type BuilderConnectionInfo, type CatalogHit, type CompiledWorkflowDto, type CreateFromPlanResponse, type OptionItem, type TableColumn, type TableItem, type ToolSchema as BuilderToolSchema, type UpdateFromPlanResponse, type WorkflowPlan, type WorkflowPublicDto, type WorkflowsListWorkflowsData } from "@engini/client";
|
|
12
|
+
import { type Transport } from "../http.js";
|
|
13
|
+
/** Minimal client surface this resource needs (satisfied by `Engini`). */
|
|
14
|
+
export interface WorkflowsClient {
|
|
15
|
+
_transport: Transport;
|
|
16
|
+
}
|
|
17
|
+
type ListQuery = NonNullable<WorkflowsListWorkflowsData["query"]>;
|
|
18
|
+
/** Filters for `workflows.list`; `top` / `offset` are handled by the method. */
|
|
19
|
+
export type WorkflowsListParams = Omit<ListQuery, "top" | "offset"> & {
|
|
20
|
+
/** With `top`, fetch one page of at most `top` rows (server cap 100) instead of draining. */
|
|
21
|
+
top?: number;
|
|
22
|
+
/** Only meaningful together with `top`. */
|
|
23
|
+
offset?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare class WorkflowsResource {
|
|
26
|
+
private readonly client;
|
|
27
|
+
constructor(client: WorkflowsClient);
|
|
28
|
+
/**
|
|
29
|
+
* Workflows the credential can see, without their steps (read one back as a plan with `getPlan`).
|
|
30
|
+
* `name` and `folderName` are case-insensitive substring matches, so several rows can match:
|
|
31
|
+
* compare `name` yourself for an exact one. `folderId` is a number here but a string on a folder
|
|
32
|
+
* (`folders.list`), and `0` means "no folder". Table automations are not listed.
|
|
33
|
+
*
|
|
34
|
+
* With no `top`, drains every match by `offset`, 100 per page. Pass `top` for one bounded page
|
|
35
|
+
* (add `offset` to read a later one); use `listPage` to get `totalCount` back.
|
|
36
|
+
* A row deleted mid-drain can still be skipped.
|
|
37
|
+
*/
|
|
38
|
+
list(params?: WorkflowsListParams): Promise<WorkflowPublicDto[]>;
|
|
39
|
+
/** One page, with its `totalCount`. */
|
|
40
|
+
listPage(params?: WorkflowsListParams): Promise<import("@engini/client").PaginatedResponseOfWorkflowPublicDto>;
|
|
41
|
+
/** Search the catalog of actions, triggers and blocks a plan step can name. */
|
|
42
|
+
searchCatalog(params?: {
|
|
43
|
+
q?: string;
|
|
44
|
+
kind?: string;
|
|
45
|
+
app?: string;
|
|
46
|
+
top?: number;
|
|
47
|
+
table?: string;
|
|
48
|
+
}): Promise<CatalogHit[]>;
|
|
49
|
+
/** The input/output schema of one catalog entry (`slug` from `searchCatalog`). */
|
|
50
|
+
getSchema(slug: string, params?: {
|
|
51
|
+
connectionId?: number;
|
|
52
|
+
kind?: string;
|
|
53
|
+
table?: string;
|
|
54
|
+
}): Promise<BuilderToolSchema>;
|
|
55
|
+
/** Dropdown values for one field of a catalog entry; `dependsOn` carries parent field values. */
|
|
56
|
+
getOptions(slug: string, params?: {
|
|
57
|
+
field?: string;
|
|
58
|
+
connectionId?: number;
|
|
59
|
+
kind?: string;
|
|
60
|
+
dependsOn?: Record<string, string>;
|
|
61
|
+
}): Promise<OptionItem[]>;
|
|
62
|
+
/** The caller's tables (an automation plan's `table` is one of these ids). */
|
|
63
|
+
listTables(): Promise<TableItem[]>;
|
|
64
|
+
/** The columns of one table, as a table automation reads them. */
|
|
65
|
+
listTableColumns(tableId: string, params?: {
|
|
66
|
+
trigger?: string;
|
|
67
|
+
}): Promise<TableColumn[]>;
|
|
68
|
+
/** Connections a plan step may bind to, optionally narrowed to one app slug. */
|
|
69
|
+
listConnections(params?: {
|
|
70
|
+
app?: string;
|
|
71
|
+
}): Promise<BuilderConnectionInfo[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Dry-run a plan: nothing is written. Check `hasErrors` / `diagnostics` on the result;
|
|
74
|
+
* a plan with errors is *returned* here, not thrown (`create`/`update` throw it).
|
|
75
|
+
* `baseWorkflowId` compiles the plan as an edit of a saved workflow.
|
|
76
|
+
*/
|
|
77
|
+
compile(params: {
|
|
78
|
+
plan?: WorkflowPlan;
|
|
79
|
+
baseWorkflowId?: number;
|
|
80
|
+
}): Promise<CompiledWorkflowDto>;
|
|
81
|
+
/** A saved workflow, read back as a plan (the input to an `update`). */
|
|
82
|
+
getPlan(workflowId: number): Promise<WorkflowPlan>;
|
|
83
|
+
/**
|
|
84
|
+
* Create a workflow from a plan, turned off. `PLAN_HAS_ERRORS` (422) is thrown as
|
|
85
|
+
* `EnginiBuilderError` with `diagnostics`, and nothing is written.
|
|
86
|
+
*/
|
|
87
|
+
create(params: {
|
|
88
|
+
plan: WorkflowPlan;
|
|
89
|
+
folderId?: number;
|
|
90
|
+
}): Promise<CreateFromPlanResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Replace a workflow's contents from a plan. Pass `expectedRevisionId` (the last
|
|
93
|
+
* `revisionId` you saw) to refuse a stale save with `REVISION_CONFLICT`
|
|
94
|
+
* (`currentRevisionId` on the error). A turned-on workflow is refused: `WORKFLOW_ACTIVE`.
|
|
95
|
+
*/
|
|
96
|
+
update(workflowId: number, params: {
|
|
97
|
+
plan: WorkflowPlan;
|
|
98
|
+
expectedRevisionId?: number;
|
|
99
|
+
}): Promise<UpdateFromPlanResponse>;
|
|
100
|
+
}
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflows resource — list workflows (`GET /v1/workflows`) and the workflow builder
|
|
3
|
+
* (`/v1/workflows*`): look up what a plan may use
|
|
4
|
+
* (catalog, schemas, options, tables, connections), dry-run a plan with `compile`, and write
|
|
5
|
+
* one with `create` / `update`.
|
|
6
|
+
*
|
|
7
|
+
* Refusals arrive as `EnginiBuilderError` (`code`, `path`, `fix`, `diagnostics`,
|
|
8
|
+
* `currentRevisionId`). Writes need a workspace-scoped API key (`SCOPE_REQUIRED` otherwise),
|
|
9
|
+
* and a workflow is always created turned off.
|
|
10
|
+
*/
|
|
11
|
+
import { workflowsCompile, workflowsCreateWorkflow, workflowsGetOptions, workflowsGetPlan, workflowsGetSchema, workflowsListConnections, workflowsListTableColumns, workflowsListTables, workflowsListWorkflows, workflowsSearchCatalog, workflowsUpdateWorkflow, } from "@engini/client";
|
|
12
|
+
import { EnginiClientError } from "../errors.js";
|
|
13
|
+
import { call } from "../http.js";
|
|
14
|
+
import { collect, paginate } from "../pagination.js";
|
|
15
|
+
export class WorkflowsResource {
|
|
16
|
+
client;
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Workflows the credential can see, without their steps (read one back as a plan with `getPlan`).
|
|
22
|
+
* `name` and `folderName` are case-insensitive substring matches, so several rows can match:
|
|
23
|
+
* compare `name` yourself for an exact one. `folderId` is a number here but a string on a folder
|
|
24
|
+
* (`folders.list`), and `0` means "no folder". Table automations are not listed.
|
|
25
|
+
*
|
|
26
|
+
* With no `top`, drains every match by `offset`, 100 per page. Pass `top` for one bounded page
|
|
27
|
+
* (add `offset` to read a later one); use `listPage` to get `totalCount` back.
|
|
28
|
+
* A row deleted mid-drain can still be skipped.
|
|
29
|
+
*/
|
|
30
|
+
async list(params = {}) {
|
|
31
|
+
const { top, offset, ...filters } = params;
|
|
32
|
+
if (top !== undefined)
|
|
33
|
+
return (await this.listPage({ ...filters, top, offset })).items ?? [];
|
|
34
|
+
if (offset !== undefined) {
|
|
35
|
+
throw new EnginiClientError("`offset` needs `top`; without `top` every page is drained from the start.");
|
|
36
|
+
}
|
|
37
|
+
const rows = await collect(paginate((skip, pageSize) => call(workflowsListWorkflows, {
|
|
38
|
+
client: this.client._transport,
|
|
39
|
+
query: { ...filters, offset: skip, top: pageSize },
|
|
40
|
+
})));
|
|
41
|
+
// A workflow created mid-drain shifts later pages and repeats a row: keep the first (rows without an id all stay).
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
return rows.filter((row) => row.workflowId == null || (!seen.has(row.workflowId) && !!seen.add(row.workflowId)));
|
|
44
|
+
}
|
|
45
|
+
/** One page, with its `totalCount`. */
|
|
46
|
+
async listPage(params = {}) {
|
|
47
|
+
return call(workflowsListWorkflows, { client: this.client._transport, query: params });
|
|
48
|
+
}
|
|
49
|
+
/** Search the catalog of actions, triggers and blocks a plan step can name. */
|
|
50
|
+
async searchCatalog(params = {}) {
|
|
51
|
+
return call(workflowsSearchCatalog, { client: this.client._transport, query: params });
|
|
52
|
+
}
|
|
53
|
+
/** The input/output schema of one catalog entry (`slug` from `searchCatalog`). */
|
|
54
|
+
async getSchema(slug, params = {}) {
|
|
55
|
+
return call(workflowsGetSchema, {
|
|
56
|
+
client: this.client._transport,
|
|
57
|
+
path: { slug },
|
|
58
|
+
query: params,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** Dropdown values for one field of a catalog entry; `dependsOn` carries parent field values. */
|
|
62
|
+
async getOptions(slug, params = {}) {
|
|
63
|
+
return call(workflowsGetOptions, {
|
|
64
|
+
client: this.client._transport,
|
|
65
|
+
path: { slug },
|
|
66
|
+
query: params,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** The caller's tables (an automation plan's `table` is one of these ids). */
|
|
70
|
+
async listTables() {
|
|
71
|
+
return call(workflowsListTables, { client: this.client._transport });
|
|
72
|
+
}
|
|
73
|
+
/** The columns of one table, as a table automation reads them. */
|
|
74
|
+
async listTableColumns(tableId, params = {}) {
|
|
75
|
+
return call(workflowsListTableColumns, {
|
|
76
|
+
client: this.client._transport,
|
|
77
|
+
path: { tableId },
|
|
78
|
+
query: params,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** Connections a plan step may bind to, optionally narrowed to one app slug. */
|
|
82
|
+
async listConnections(params = {}) {
|
|
83
|
+
return call(workflowsListConnections, { client: this.client._transport, query: params });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Dry-run a plan: nothing is written. Check `hasErrors` / `diagnostics` on the result;
|
|
87
|
+
* a plan with errors is *returned* here, not thrown (`create`/`update` throw it).
|
|
88
|
+
* `baseWorkflowId` compiles the plan as an edit of a saved workflow.
|
|
89
|
+
*/
|
|
90
|
+
async compile(params) {
|
|
91
|
+
return call(workflowsCompile, { client: this.client._transport, body: params });
|
|
92
|
+
}
|
|
93
|
+
/** A saved workflow, read back as a plan (the input to an `update`). */
|
|
94
|
+
async getPlan(workflowId) {
|
|
95
|
+
return call(workflowsGetPlan, {
|
|
96
|
+
client: this.client._transport,
|
|
97
|
+
path: { workflowId },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create a workflow from a plan, turned off. `PLAN_HAS_ERRORS` (422) is thrown as
|
|
102
|
+
* `EnginiBuilderError` with `diagnostics`, and nothing is written.
|
|
103
|
+
*/
|
|
104
|
+
async create(params) {
|
|
105
|
+
return call(workflowsCreateWorkflow, { client: this.client._transport, body: params });
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Replace a workflow's contents from a plan. Pass `expectedRevisionId` (the last
|
|
109
|
+
* `revisionId` you saw) to refuse a stale save with `REVISION_CONFLICT`
|
|
110
|
+
* (`currentRevisionId` on the error). A turned-on workflow is refused: `WORKFLOW_ACTIVE`.
|
|
111
|
+
*/
|
|
112
|
+
async update(workflowId, params) {
|
|
113
|
+
return call(workflowsUpdateWorkflow, {
|
|
114
|
+
client: this.client._transport,
|
|
115
|
+
path: { workflowId },
|
|
116
|
+
body: params,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Engini SDK — agent-first ergonomic layer over the Engini Public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"test": "vitest run"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@engini/client": "0.
|
|
30
|
+
"@engini/client": "0.18.0",
|
|
31
31
|
"undici": "^6.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|