@engini/sdk 0.34.0 → 0.36.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 CHANGED
@@ -31,6 +31,18 @@ JWT auth is the fallback: `new Engini({ token: "<jwt>", companyToken: "<id>" })`
31
31
  `ENGINI_API_TOKEN` / `ENGINI_COMPANY_TOKEN`. With an API key the company is bound to the key,
32
32
  so no company token is needed. Point at another host with `new Engini({ …, baseUrl })`.
33
33
 
34
+ A person token (not an API key) can reach several workspaces. Name the one to act in with
35
+ `workspaceId` and `environmentId` (GUIDs, always together):
36
+
37
+ ```ts
38
+ const client = new Engini({ token: "<token>", workspaceId: "<ws-guid>", environmentId: "<env-guid>" });
39
+ ```
40
+
41
+ With neither, lists cover every workspace/environment you can open and a create lands in the
42
+ account's default workspace. An API key is already pinned to one pair, so passing a pair with
43
+ `apiKey` throws. The pair travels as headers for now; a later release moves it into list filters
44
+ and create bodies without changing these options.
45
+
34
46
  Every request carries a `User-Agent` identifying this SDK and its runtime (e.g.
35
47
  `engini-sdk-ts/0.13.0 node/20.11.0 darwin-arm64`). If you're embedding the SDK inside your own
36
48
  product, prepend your own token with `userAgentPrefix`:
@@ -200,8 +212,8 @@ for await (const event of client.triggers.subscribe({
200
212
 
201
213
  ## Executions
202
214
 
203
- `client.executions` is the read-only run history of workflows, table automations and
204
- business rules (no rerun):
215
+ `client.executions` is the run history of workflows, table automations and
216
+ business rules, and `rerun` runs one again:
205
217
 
206
218
  ```ts
207
219
  // Every failed run of one workflow. With no `top` this follows `nextCursor` until it is
@@ -223,6 +235,30 @@ const slowest = (await client.executions.data(4567, 3, { type: "status" }))
223
235
  Sorting by `closedAt` (or several keys) has no cursor on the server, so `list` drains those
224
236
  by `offset` instead.
225
237
 
238
+ ```ts
239
+ const again = await client.executions.rerun(4567); // the new execution; EnginiConflictError (409) if it cannot be re-run
240
+ ```
241
+
242
+ `rerun` needs a workspace-scoped API key (an unscoped key gets `EnginiAuthError`, `errorCode`
243
+ `SCOPE_READ_ONLY`) and has no idempotency key: a retry after a lost answer starts a second run.
244
+
245
+ ## Reading and running a workflow
246
+
247
+ `workflows.get` returns one workflow with its steps (and `webhookUrl` for a webhook trigger - its token
248
+ authorizes calls to it, so treat it like a credential); `workflows.revisions` returns one page of its stored
249
+ revisions, newest first. `setEnabled`, `delete` and `run` change state and need a workspace-scoped API key
250
+ (an unscoped key gets `EnginiAuthError` with `errorCode` `SCOPE_READ_ONLY`; reads still work). `delete` is a
251
+ soft delete and succeeds for an already-deleted workflow. `run` starts one run now, even for a turned-off
252
+ workflow, and has no idempotency key: a retry after a lost answer starts a second run.
253
+
254
+ ```ts
255
+ const wf = await client.workflows.get(1234); // wf.steps, wf.webhookUrl
256
+ const revs = await client.workflows.revisions(1234, { top: 10 }); // { items, totalCount, offset, top }
257
+ await client.workflows.setEnabled(1234, true);
258
+ const execution = await client.workflows.run(1234, { email: "a@b.co" }); // trigger payload, default {}
259
+ await client.workflows.delete(1234);
260
+ ```
261
+
226
262
  ## Building workflows
227
263
 
228
264
  `client.workflows` is the workflow builder: look up what a plan may use, dry-run it, then
package/dist/client.d.ts CHANGED
@@ -48,7 +48,28 @@ export interface EnginiOptions {
48
48
  * control character or exceeds 128 characters.
49
49
  */
50
50
  userAgentPrefix?: string;
51
+ /**
52
+ * Workspace to act in (a GUID), for a person token (`token`/`auth`) that can
53
+ * reach several workspaces. Pass it together with `environmentId`, or neither:
54
+ * with neither, the server decides (lists cover every pair you can open; a
55
+ * create lands in the account's default workspace). Not allowed with api-key
56
+ * auth - a key is already pinned to one workspace and environment.
57
+ *
58
+ * Sent as the `workspaceId` header for now; a later release moves it to list
59
+ * filters and create bodies inside the SDK, without changing this option.
60
+ */
61
+ workspaceId?: string;
62
+ /** Environment to act in (a GUID); always together with `workspaceId`. */
63
+ environmentId?: string;
51
64
  }
65
+ /**
66
+ * Validate the client-level workspace/environment pair: both or neither,
67
+ * GUID-shaped. Returns the pair, or `undefined` when neither is given.
68
+ */
69
+ export declare function validateScopePair(workspaceId: string | undefined, environmentId: string | undefined): {
70
+ workspaceId: string;
71
+ environmentId: string;
72
+ } | undefined;
52
73
  /** Engini SDK client — the single public entry point. */
53
74
  export declare class Engini {
54
75
  readonly tools: ToolsResource;
package/dist/client.js CHANGED
@@ -16,6 +16,25 @@ import { ApplicationsResource } from "./resources/applications.js";
16
16
  import { AuthResource } from "./resources/auth.js";
17
17
  import { Toolset } from "./toolset.js";
18
18
  export const DEFAULT_BASE_URL = "https://api.engini.io";
19
+ const GUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
20
+ /**
21
+ * Validate the client-level workspace/environment pair: both or neither,
22
+ * GUID-shaped. Returns the pair, or `undefined` when neither is given.
23
+ */
24
+ export function validateScopePair(workspaceId, environmentId) {
25
+ if (workspaceId === undefined && environmentId === undefined)
26
+ return undefined;
27
+ if (workspaceId === undefined || environmentId === undefined) {
28
+ throw new EnginiClientError("Pass both `workspaceId` and `environmentId`, or neither.");
29
+ }
30
+ if (!GUID_RE.test(workspaceId)) {
31
+ throw new EnginiClientError("`workspaceId` must be a GUID.");
32
+ }
33
+ if (!GUID_RE.test(environmentId)) {
34
+ throw new EnginiClientError("`environmentId` must be a GUID.");
35
+ }
36
+ return { workspaceId, environmentId };
37
+ }
19
38
  /** Engini SDK client — the single public entry point. */
20
39
  export class Engini {
21
40
  tools;
@@ -71,10 +90,15 @@ export class Engini {
71
90
  const companyToken = isApiKey
72
91
  ? undefined
73
92
  : (options.companyToken ?? process.env[ENV_COMPANY_TOKEN_VAR]);
93
+ const scope = validateScopePair(options.workspaceId, options.environmentId);
94
+ if (isApiKey && scope !== undefined) {
95
+ throw new EnginiClientError("`workspaceId`/`environmentId` are not used with api-key auth; the key is pinned to one workspace and environment.");
96
+ }
74
97
  this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
75
98
  this._transport = buildClient(this.baseUrl, auth, companyToken, {
76
99
  verify: options.verify ?? true,
77
100
  userAgentPrefix: options.userAgentPrefix,
101
+ scope,
78
102
  });
79
103
  this.provider = options.provider ?? new OpenAIProvider();
80
104
  this.tools = new ToolsResource(this);
package/dist/http.d.ts CHANGED
@@ -47,6 +47,10 @@ export declare function composeUserAgent(prefix?: string): string;
47
47
  export declare function buildClient(baseUrl: string, auth: Auth, companyToken?: string, options?: {
48
48
  verify?: Verify;
49
49
  userAgentPrefix?: string;
50
+ scope?: {
51
+ workspaceId: string;
52
+ environmentId: string;
53
+ };
50
54
  }): Transport;
51
55
  /** A generated operation function (hey-api), invoked with `{ client, ... }`. */
52
56
  type Operation<O, R> = (options: O & {
package/dist/http.js CHANGED
@@ -82,6 +82,12 @@ export function buildClient(baseUrl, auth, companyToken, options = {}) {
82
82
  headers.set(key, value);
83
83
  if (companyToken !== undefined)
84
84
  headers.set("companytoken", companyToken);
85
+ // Stopgap transport for the client-level pair: the server reads these headers
86
+ // today; a later release moves the pair into list filters / create bodies.
87
+ if (options.scope !== undefined) {
88
+ headers.set("workspaceId", options.scope.workspaceId);
89
+ headers.set("environmentId", options.scope.environmentId);
90
+ }
85
91
  headers.set("user-agent", composeUserAgent(options.userAgentPrefix));
86
92
  const dispatcher = tlsDispatcher(options.verify ?? true);
87
93
  const fetchOverride = dispatcher === undefined
@@ -1,6 +1,6 @@
1
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.
2
+ * Executions resource — history of workflow, table-automation and business-rule runs
3
+ * (`/v1/executions*`), and `rerun` to run one again.
4
4
  */
5
5
  import { type ExecutionDataEntryPublicDto, type ExecutionLogEntryPublicDto, type ExecutionPublicDto, type ExecutionsListExecutionsData } from "@engini/client";
6
6
  import { type Transport } from "../http.js";
@@ -39,6 +39,13 @@ export declare class ExecutionsResource {
39
39
  listPage(params?: ExecutionsListParams): Promise<import("@engini/client").CursorPaginatedResponseOfExecutionPublicDto>;
40
40
  /** One execution. */
41
41
  get(executionId: number): Promise<ExecutionPublicDto>;
42
+ /**
43
+ * Run an execution again; returns the new execution. A run that is still in progress, or of
44
+ * a kind that cannot be re-run, or an account limit, is refused with `EnginiConflictError`
45
+ * (409). Needs a workspace-scoped API key: 403 `SCOPE_READ_ONLY` otherwise. There is no
46
+ * idempotency key: a retry after a lost answer starts a second run.
47
+ */
48
+ rerun(executionId: number): Promise<ExecutionPublicDto>;
42
49
  /**
43
50
  * The execution's per-step log. A 410 (retention window passed) throws
44
51
  * `EnginiAPIError` — the execution itself is still listed.
@@ -1,8 +1,8 @@
1
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.
2
+ * Executions resource — history of workflow, table-automation and business-rule runs
3
+ * (`/v1/executions*`), and `rerun` to run one again.
4
4
  */
5
- import { executionsGetExecution, executionsGetExecutionLog, executionsListExecutionData, executionsListExecutions, } from "@engini/client";
5
+ import { executionsGetExecution, executionsGetExecutionLog, executionsListExecutionData, executionsListExecutions, executionsRerunExecution, } from "@engini/client";
6
6
  import { EnginiClientError } from "../errors.js";
7
7
  import { call } from "../http.js";
8
8
  import { collect, paginate, paginateCursor } from "../pagination.js";
@@ -67,6 +67,18 @@ export class ExecutionsResource {
67
67
  path: { executionId },
68
68
  });
69
69
  }
70
+ /**
71
+ * Run an execution again; returns the new execution. A run that is still in progress, or of
72
+ * a kind that cannot be re-run, or an account limit, is refused with `EnginiConflictError`
73
+ * (409). Needs a workspace-scoped API key: 403 `SCOPE_READ_ONLY` otherwise. There is no
74
+ * idempotency key: a retry after a lost answer starts a second run.
75
+ */
76
+ async rerun(executionId) {
77
+ return call(executionsRerunExecution, {
78
+ client: this.client._transport,
79
+ path: { executionId },
80
+ });
81
+ }
70
82
  /**
71
83
  * The execution's per-step log. A 410 (retention window passed) throws
72
84
  * `EnginiAPIError` — the execution itself is still listed.
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Workflows resource — list workflows (`GET /v1/workflows`) and the workflow builder
2
+ * Workflows resource — list workflows (`GET /v1/workflows`), read one (`get`, `revisions`), turn
3
+ * one on or off, delete it, run it (`setEnabled`, `delete`, `run`), and the workflow builder
3
4
  * (`/v1/workflows*`): look up what a plan may use
4
5
  * (catalog, schemas, options, tables, connections), dry-run a plan with `compile`, and write
5
6
  * one with `create` / `update`.
@@ -8,13 +9,15 @@
8
9
  * `currentRevisionId`). Writes need a workspace-scoped API key (`SCOPE_REQUIRED` otherwise),
9
10
  * and a workflow is always created turned off.
10
11
  */
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 BuilderConnectionInfo, type CatalogHit, type CompiledWorkflowDto, type CreateFromPlanResponse, type ExecutionPublicDto, type OptionItem, type PaginatedResponseOfWorkflowRevisionPublicDto, type TableColumn, type TableItem, type ToolSchema as BuilderToolSchema, type UpdateFromPlanResponse, type WorkflowDetailPublicDto, type WorkflowPlan, type WorkflowPublicDto, type WorkflowsListRevisionsData, type WorkflowsListWorkflowsData } from "@engini/client";
12
13
  import { type Transport } from "../http.js";
13
14
  /** Minimal client surface this resource needs (satisfied by `Engini`). */
14
15
  export interface WorkflowsClient {
15
16
  _transport: Transport;
16
17
  }
17
18
  type ListQuery = NonNullable<WorkflowsListWorkflowsData["query"]>;
19
+ /** Filters, sort and paging for `workflows.revisions` (one page; `top` is capped at 100 by the server). */
20
+ export type WorkflowRevisionsParams = NonNullable<WorkflowsListRevisionsData["query"]>;
18
21
  /** Filters for `workflows.list`; `top` / `offset` are handled by the method. */
19
22
  export type WorkflowsListParams = Omit<ListQuery, "top" | "offset"> & {
20
23
  /** With `top`, fetch one page of at most `top` rows (server cap 100) instead of draining. */
@@ -38,6 +41,34 @@ export declare class WorkflowsResource {
38
41
  list(params?: WorkflowsListParams): Promise<WorkflowPublicDto[]>;
39
42
  /** One page, with its `totalCount`. */
40
43
  listPage(params?: WorkflowsListParams): Promise<import("@engini/client").PaginatedResponseOfWorkflowPublicDto>;
44
+ /**
45
+ * One workflow with its steps. `webhookUrl` is present only for a webhook trigger Engini hands
46
+ * out; the token inside it authorizes calls to it, so treat it like a credential.
47
+ */
48
+ get(workflowId: number): Promise<WorkflowDetailPublicDto>;
49
+ /**
50
+ * One page of a workflow's stored revisions, newest first by default (`revisionId desc`),
51
+ * with `totalCount`. Restoring a revision is not part of the API.
52
+ */
53
+ revisions(workflowId: number, params?: WorkflowRevisionsParams): Promise<PaginatedResponseOfWorkflowRevisionPublicDto>;
54
+ /**
55
+ * Turn a workflow on or off; returns the workflow as it stands afterwards. Needs a
56
+ * workspace-scoped API key (an unscoped key is refused 403 `SCOPE_READ_ONLY`). Turning on a
57
+ * workflow created through the API is how it starts listening: it is always created off.
58
+ */
59
+ setEnabled(workflowId: number, enabled: boolean): Promise<WorkflowPublicDto>;
60
+ /**
61
+ * Delete a workflow (a soft delete). Succeeds, with no result, for an already-deleted one.
62
+ * Needs a workspace-scoped API key: 403 `SCOPE_READ_ONLY` otherwise.
63
+ */
64
+ delete(workflowId: number): Promise<void>;
65
+ /**
66
+ * Start one run now; `body` is the trigger payload handed to the workflow's trigger step.
67
+ * Returns the execution that was started (read its outcome with `executions.get`). A
68
+ * disabled or blocked workflow may still be run this way. There is no idempotency key: a
69
+ * retry after a lost answer starts a second run.
70
+ */
71
+ run(workflowId: number, body?: Record<string, unknown>): Promise<ExecutionPublicDto>;
41
72
  /** Search the catalog of actions, triggers and blocks a plan step can name. */
42
73
  searchCatalog(params?: {
43
74
  q?: string;
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Workflows resource — list workflows (`GET /v1/workflows`) and the workflow builder
2
+ * Workflows resource — list workflows (`GET /v1/workflows`), read one (`get`, `revisions`), turn
3
+ * one on or off, delete it, run it (`setEnabled`, `delete`, `run`), and the workflow builder
3
4
  * (`/v1/workflows*`): look up what a plan may use
4
5
  * (catalog, schemas, options, tables, connections), dry-run a plan with `compile`, and write
5
6
  * one with `create` / `update`.
@@ -8,7 +9,7 @@
8
9
  * `currentRevisionId`). Writes need a workspace-scoped API key (`SCOPE_REQUIRED` otherwise),
9
10
  * and a workflow is always created turned off.
10
11
  */
11
- import { workflowsCompile, workflowsCreateWorkflow, workflowsGetOptions, workflowsGetPlan, workflowsGetSchema, workflowsListConnections, workflowsListTableColumns, workflowsListTables, workflowsListWorkflows, workflowsSearchCatalog, workflowsUpdateWorkflow, } from "@engini/client";
12
+ import { workflowsCompile, workflowsCreateWorkflow, workflowsDeleteWorkflow, workflowsGetOptions, workflowsGetPlan, workflowsGetSchema, workflowsGetWorkflow, workflowsListConnections, workflowsListRevisions, workflowsListTableColumns, workflowsListTables, workflowsListWorkflows, workflowsRunWorkflow, workflowsSearchCatalog, workflowsSetWorkflowEnabled, workflowsUpdateWorkflow, } from "@engini/client";
12
13
  import { EnginiClientError } from "../errors.js";
13
14
  import { call } from "../http.js";
14
15
  import { collect, paginate } from "../pagination.js";
@@ -46,6 +47,56 @@ export class WorkflowsResource {
46
47
  async listPage(params = {}) {
47
48
  return call(workflowsListWorkflows, { client: this.client._transport, query: params });
48
49
  }
50
+ /**
51
+ * One workflow with its steps. `webhookUrl` is present only for a webhook trigger Engini hands
52
+ * out; the token inside it authorizes calls to it, so treat it like a credential.
53
+ */
54
+ async get(workflowId) {
55
+ return call(workflowsGetWorkflow, { client: this.client._transport, path: { workflowId } });
56
+ }
57
+ /**
58
+ * One page of a workflow's stored revisions, newest first by default (`revisionId desc`),
59
+ * with `totalCount`. Restoring a revision is not part of the API.
60
+ */
61
+ async revisions(workflowId, params = {}) {
62
+ return call(workflowsListRevisions, {
63
+ client: this.client._transport,
64
+ path: { workflowId },
65
+ query: params,
66
+ });
67
+ }
68
+ /**
69
+ * Turn a workflow on or off; returns the workflow as it stands afterwards. Needs a
70
+ * workspace-scoped API key (an unscoped key is refused 403 `SCOPE_READ_ONLY`). Turning on a
71
+ * workflow created through the API is how it starts listening: it is always created off.
72
+ */
73
+ async setEnabled(workflowId, enabled) {
74
+ return call(workflowsSetWorkflowEnabled, {
75
+ client: this.client._transport,
76
+ path: { workflowId },
77
+ body: { enabled },
78
+ });
79
+ }
80
+ /**
81
+ * Delete a workflow (a soft delete). Succeeds, with no result, for an already-deleted one.
82
+ * Needs a workspace-scoped API key: 403 `SCOPE_READ_ONLY` otherwise.
83
+ */
84
+ async delete(workflowId) {
85
+ await call(workflowsDeleteWorkflow, { client: this.client._transport, path: { workflowId } });
86
+ }
87
+ /**
88
+ * Start one run now; `body` is the trigger payload handed to the workflow's trigger step.
89
+ * Returns the execution that was started (read its outcome with `executions.get`). A
90
+ * disabled or blocked workflow may still be run this way. There is no idempotency key: a
91
+ * retry after a lost answer starts a second run.
92
+ */
93
+ async run(workflowId, body = {}) {
94
+ return call(workflowsRunWorkflow, {
95
+ client: this.client._transport,
96
+ path: { workflowId },
97
+ body,
98
+ });
99
+ }
49
100
  /** Search the catalog of actions, triggers and blocks a plan step can name. */
50
101
  async searchCatalog(params = {}) {
51
102
  return call(workflowsSearchCatalog, { client: this.client._transport, query: params });
package/dist/version.d.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * Regenerated on every build/typecheck/test (see the "pre*" scripts in
4
4
  * package.json). Un-stamped local builds yield "0.0.0".
5
5
  */
6
- export declare const VERSION = "0.34.0";
6
+ export declare const VERSION = "0.36.0";
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Regenerated on every build/typecheck/test (see the "pre*" scripts in
4
4
  * package.json). Un-stamped local builds yield "0.0.0".
5
5
  */
6
- export const VERSION = "0.34.0";
6
+ export const VERSION = "0.36.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/sdk",
3
- "version": "0.34.0",
3
+ "version": "0.36.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.21.0",
30
+ "@engini/client": "0.22.0",
31
31
  "undici": "^6.0.0"
32
32
  },
33
33
  "devDependencies": {