@engini/sdk 0.18.0 → 0.20.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 +81 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +6 -0
- package/dist/errors.d.ts +108 -2
- package/dist/errors.js +95 -2
- package/dist/http.d.ts +17 -0
- package/dist/http.js +47 -5
- package/dist/index.d.ts +6 -3
- package/dist/index.js +2 -2
- package/dist/resources/index.d.ts +4 -0
- package/dist/resources/index.js +2 -0
- package/dist/resources/opa.d.ts +175 -0
- package/dist/resources/opa.js +322 -0
- package/dist/resources/triggers.d.ts +355 -0
- package/dist/resources/triggers.js +851 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -72,6 +72,87 @@ const tools = await client.mcp.availableTools(token, 2139); // candidates for
|
|
|
72
72
|
connection entry needs an explicit `connectionId` (MCP servers are account-wide, so there
|
|
73
73
|
is no per-user default). There is no `create`/`delete`: those stay in the engini.io UI.
|
|
74
74
|
|
|
75
|
+
`client.opa` provisions, inspects, configures and credentials on-premise agents — the
|
|
76
|
+
Engini component a customer installs behind their own firewall to reach SQL Server,
|
|
77
|
+
Oracle, Priority ERP and file shares:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// Provision one and hand the token to the installer
|
|
81
|
+
const agent = await client.opa.create({ name: "Warehouse SQL", pullPeriodSeconds: 30 });
|
|
82
|
+
console.log(agent.token); // a credential - store it, do not log it
|
|
83
|
+
|
|
84
|
+
// Later: is it healthy?
|
|
85
|
+
const a = await client.opa.get(agent.agentId);
|
|
86
|
+
console.log(a.status, a.version, a.lastSeenAt);
|
|
87
|
+
|
|
88
|
+
// Change its log level; the agent picks it up on its next poll
|
|
89
|
+
const r = await client.opa.update(agent.agentId, { logLevel: "Debug" });
|
|
90
|
+
if (!r.appliedToAgent) console.log("stored; the agent is not Online yet");
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
An agent polls Engini, so anything that "talks to" it waits for its next poll. `update()`
|
|
94
|
+
**merges** — an omitted member leaves that field alone, unlike `connections.update()`,
|
|
95
|
+
which replaces its whole field map. Settings you omit take the server's defaults, and the
|
|
96
|
+
minimums come from the connector's own declared metadata rather than the client. Agents are
|
|
97
|
+
not connections: `client.connections` never returns them.
|
|
98
|
+
|
|
99
|
+
`client.triggers` is the event side of the platform: a trigger instance (`ti_…`) watches a
|
|
100
|
+
connected system and captures events, which Engini POSTs to a destination you register.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
// What can be triggered, then one instance of it
|
|
104
|
+
const types = await client.triggers.types.list({ applicationSlug: "monday" });
|
|
105
|
+
const trigger = await client.triggers.create({
|
|
106
|
+
triggerSlug: "monday_item_created",
|
|
107
|
+
connectionName: "prod",
|
|
108
|
+
});
|
|
109
|
+
await client.triggers.enable(trigger.id!);
|
|
110
|
+
|
|
111
|
+
// Where events are delivered. The secret is shown once - store it, never log it.
|
|
112
|
+
const created = await client.triggers.destinations.create({
|
|
113
|
+
name: "primary",
|
|
114
|
+
url: "https://acme.test/hooks/engini",
|
|
115
|
+
});
|
|
116
|
+
const signingSecret = created.signing_secret;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Verify a delivery in your HTTP handler. `verifyWebhook` **throws** rather than returning a
|
|
120
|
+
boolean — a boolean is silently ignorable, which is the one failure mode a signature check
|
|
121
|
+
cannot afford — and hands back the parsed event so it is one call, not two:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { verifyWebhook, EnginiWebhookSignatureError } from "@engini/sdk";
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
// The raw body, not a re-serialised one. Node lower-cases header names and types
|
|
128
|
+
// them `string | string[] | undefined`, so narrow before passing.
|
|
129
|
+
const signature = req.headers["x-engini-signature"];
|
|
130
|
+
const event = verifyWebhook(
|
|
131
|
+
rawBody,
|
|
132
|
+
Array.isArray(signature) ? signature[0] : signature,
|
|
133
|
+
signingSecret,
|
|
134
|
+
);
|
|
135
|
+
// … dedupe on the X-Engini-Event-Id header
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (err instanceof EnginiWebhookSignatureError) return res.status(400).end();
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
For local development `subscribe()` reads the same events as an async iterator. It resumes
|
|
143
|
+
by itself, which is not a nicety: the gateway caps every connection at one hour of
|
|
144
|
+
wall-clock time, and the cut arrives as a truncated body with no goodbye. It reconnects
|
|
145
|
+
from the last event you saw, and stops hard only where a gap would otherwise go unnoticed —
|
|
146
|
+
a revoked stream, or a cursor the server has already pruned.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
for await (const event of client.triggers.subscribe({ triggerId: trigger.id })) {
|
|
150
|
+
console.log(event.id, event.payload);
|
|
151
|
+
// `event.delivery` is always "pending" on the stream - it is not a delivery state.
|
|
152
|
+
// Use client.triggers.events.get(event.id!) for the real one.
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
75
156
|
`client.toolset(...)` builds a local toolset (no I/O until used) or loads a server one via
|
|
76
157
|
`client.toolset({ toolsetId })`.
|
|
77
158
|
|
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { ToolsResource } from "./resources/tools.js";
|
|
|
5
5
|
import { ConnectionsResource } from "./resources/connections.js";
|
|
6
6
|
import { ToolsetsResource } from "./resources/toolsets.js";
|
|
7
7
|
import { McpResource } from "./resources/mcp.js";
|
|
8
|
+
import { OpaResource } from "./resources/opa.js";
|
|
9
|
+
import { TriggersResource } from "./resources/triggers.js";
|
|
8
10
|
import { ApplicationsResource } from "./resources/applications.js";
|
|
9
11
|
import { AuthResource } from "./resources/auth.js";
|
|
10
12
|
import { Toolset, type ConnectionBinding } from "./toolset.js";
|
|
@@ -49,6 +51,8 @@ export declare class Engini {
|
|
|
49
51
|
readonly connections: ConnectionsResource;
|
|
50
52
|
readonly toolsets: ToolsetsResource;
|
|
51
53
|
readonly mcp: McpResource;
|
|
54
|
+
readonly opa: OpaResource;
|
|
55
|
+
readonly triggers: TriggersResource;
|
|
52
56
|
readonly applications: ApplicationsResource;
|
|
53
57
|
readonly auth: AuthResource;
|
|
54
58
|
readonly provider: Provider;
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,8 @@ import { ToolsResource } from "./resources/tools.js";
|
|
|
6
6
|
import { ConnectionsResource } from "./resources/connections.js";
|
|
7
7
|
import { ToolsetsResource } from "./resources/toolsets.js";
|
|
8
8
|
import { McpResource } from "./resources/mcp.js";
|
|
9
|
+
import { OpaResource } from "./resources/opa.js";
|
|
10
|
+
import { TriggersResource } from "./resources/triggers.js";
|
|
9
11
|
import { ApplicationsResource } from "./resources/applications.js";
|
|
10
12
|
import { AuthResource } from "./resources/auth.js";
|
|
11
13
|
import { Toolset } from "./toolset.js";
|
|
@@ -16,6 +18,8 @@ export class Engini {
|
|
|
16
18
|
connections;
|
|
17
19
|
toolsets;
|
|
18
20
|
mcp;
|
|
21
|
+
opa;
|
|
22
|
+
triggers;
|
|
19
23
|
applications;
|
|
20
24
|
auth;
|
|
21
25
|
provider;
|
|
@@ -69,6 +73,8 @@ export class Engini {
|
|
|
69
73
|
this.connections = new ConnectionsResource(this);
|
|
70
74
|
this.toolsets = new ToolsetsResource(this);
|
|
71
75
|
this.mcp = new McpResource(this);
|
|
76
|
+
this.opa = new OpaResource(this);
|
|
77
|
+
this.triggers = new TriggersResource(this);
|
|
72
78
|
this.applications = new ApplicationsResource(this);
|
|
73
79
|
this.auth = new AuthResource(this);
|
|
74
80
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -8,8 +8,32 @@ export declare class EnginiError extends Error {
|
|
|
8
8
|
/** Transport-level failure before a response was received. */
|
|
9
9
|
export declare class EnginiNetworkError extends EnginiError {
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Any non-2xx API response with a parseable body.
|
|
13
|
+
*
|
|
14
|
+
* `errorCode` is the wire `ErrorResponse.errorCode` when the body parsed, else
|
|
15
|
+
* `undefined`; `details` is the wire `details[]`, else `[]`.
|
|
16
|
+
*
|
|
17
|
+
* Both exist because a status code stopped being enough to describe an error:
|
|
18
|
+
* three OPA conditions share 409/5xx and differ only by `errorCode`, and
|
|
19
|
+
* `OPA_APPLICATION_AMBIGUOUS` carries its candidate slugs in `details` — the only
|
|
20
|
+
* place a caller can learn them. `message` is unchanged, so code reading it is
|
|
21
|
+
* unaffected.
|
|
22
|
+
*
|
|
23
|
+
* `retryAfter` is the response's `Retry-After` header in seconds, or `undefined`
|
|
24
|
+
* when it was absent or unparseable. Only 429s set it in practice; it lives on
|
|
25
|
+
* the base so every mapped class shares one constructor signature.
|
|
26
|
+
*/
|
|
27
|
+
export interface EnginiAPIErrorOptions {
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
details?: unknown[];
|
|
30
|
+
retryAfter?: number;
|
|
31
|
+
}
|
|
12
32
|
export declare class EnginiAPIError extends EnginiError {
|
|
33
|
+
readonly errorCode: string | undefined;
|
|
34
|
+
readonly details: unknown[];
|
|
35
|
+
readonly retryAfter: number | undefined;
|
|
36
|
+
constructor(message: string, options?: EnginiAPIErrorOptions);
|
|
13
37
|
}
|
|
14
38
|
/** 401 or 403 — token missing, invalid, expired, or lacking permission. */
|
|
15
39
|
export declare class EnginiAuthError extends EnginiAPIError {
|
|
@@ -20,7 +44,7 @@ export declare class EnginiNotFoundError extends EnginiAPIError {
|
|
|
20
44
|
/** 400 or 422 — request rejected; exposes field-level details (Phase 3). */
|
|
21
45
|
export declare class EnginiValidationError extends EnginiAPIError {
|
|
22
46
|
}
|
|
23
|
-
/** 429 — rate limited
|
|
47
|
+
/** 429 — rate limited. `retryAfter` carries the `Retry-After` header in seconds. */
|
|
24
48
|
export declare class EnginiRateLimitError extends EnginiAPIError {
|
|
25
49
|
}
|
|
26
50
|
/** 409 — the request conflicts with current resource state. */
|
|
@@ -71,3 +95,85 @@ export declare class EnginiToolExecutionError extends EnginiError {
|
|
|
71
95
|
historyId?: number | null;
|
|
72
96
|
});
|
|
73
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* No on-premise agent with that id is visible to this account. Also thrown when the id
|
|
100
|
+
* exists but belongs to another account, or is not an OPA agent at all — the API answers
|
|
101
|
+
* 404 for all three deliberately, so the endpoint cannot be used to probe which ids exist
|
|
102
|
+
* in other tenants.
|
|
103
|
+
*/
|
|
104
|
+
export declare class EnginiOpaAgentNotFoundError extends EnginiNotFoundError {
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The agent is not Online, so an operation needing a live round-trip cannot run
|
|
108
|
+
* (wire code `OPA_AGENT_OFFLINE`). Thrown by `logs`. A settings update does *not* throw
|
|
109
|
+
* this: it persists the change and reports `appliedToAgent: false` instead, so the caller
|
|
110
|
+
* knows the write landed but the agent has not seen it.
|
|
111
|
+
*/
|
|
112
|
+
export declare class EnginiOpaAgentOfflineError extends EnginiConflictError {
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* More than one on-premise-agent application exists; `create` needs an `applicationSlug`
|
|
116
|
+
* (wire code `OPA_APPLICATION_AMBIGUOUS`). `candidateSlugs` is the only place a caller can
|
|
117
|
+
* learn them: `/v1/applications` does not list OPA applications.
|
|
118
|
+
*/
|
|
119
|
+
export declare class EnginiOpaApplicationAmbiguousError extends EnginiConflictError {
|
|
120
|
+
readonly candidateSlugs: string[];
|
|
121
|
+
constructor(message: string, candidateSlugs: string[], options?: EnginiAPIErrorOptions);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The agent did not answer a live round-trip within the server's bound (wire code
|
|
125
|
+
* `OPA_AGENT_TIMEOUT`, 504). Extends `EnginiServerError` rather than `EnginiTimeoutError`:
|
|
126
|
+
* that one is a *client-side* deadline outside the API-error tree, whereas this is a
|
|
127
|
+
* server-reported outcome carrying an `errorCode`.
|
|
128
|
+
*/
|
|
129
|
+
export declare class EnginiOpaAgentTimeoutError extends EnginiServerError {
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The agent was reached but reported a failure collecting or applying
|
|
133
|
+
* (wire code `OPA_AGENT_DISPATCH_FAILED`, 502).
|
|
134
|
+
*/
|
|
135
|
+
export declare class EnginiOpaAgentDispatchError extends EnginiServerError {
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The `since` cursor is older than the server's retained event window
|
|
139
|
+
* (wire code `SINCE_PRUNED`, 410).
|
|
140
|
+
*
|
|
141
|
+
* A hard stop for `triggers.subscribe`, never a silent restart: the whole point of
|
|
142
|
+
* `since` is that a gap in the stream is visible to the caller, so resuming from
|
|
143
|
+
* "now" would reintroduce exactly the invisible data loss the cursor exists to
|
|
144
|
+
* prevent. Recover by reading the missed events with `triggers.events.list` and
|
|
145
|
+
* subscribing again.
|
|
146
|
+
*
|
|
147
|
+
* 410 is the one trigger status with no row in `STATUS_TO_ERROR`; the retype
|
|
148
|
+
* happens on `errorCode` like the rest of this family.
|
|
149
|
+
*/
|
|
150
|
+
export declare class EnginiTriggerGapError extends EnginiAPIError {
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Engini could not establish the upstream subscription with the provider
|
|
154
|
+
* (wire code `TRIGGER_SUBSCRIBE_FAILED`, 502). The trigger exists but is not
|
|
155
|
+
* receiving events; the provider rejected or dropped the registration.
|
|
156
|
+
*/
|
|
157
|
+
export declare class EnginiTriggerSubscribeFailedError extends EnginiServerError {
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Too many concurrent SSE streams are open for this account (wire code
|
|
161
|
+
* `TRIGGER_STREAM_LIMIT_EXCEEDED`, 429). `retryAfter` carries the server's
|
|
162
|
+
* `Retry-After` in seconds, which `triggers.subscribe` honours before it retries.
|
|
163
|
+
*/
|
|
164
|
+
export declare class EnginiTriggerStreamLimitError extends EnginiRateLimitError {
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A delivered webhook failed signature verification.
|
|
168
|
+
*
|
|
169
|
+
* Thrown by `verifyWebhook` for every rejection — a bad or absent signature, a
|
|
170
|
+
* malformed header, an unknown scheme version, or a timestamp outside the replay
|
|
171
|
+
* tolerance. Deliberately outside the `EnginiAPIError` tree: nothing here came
|
|
172
|
+
* from an Engini API response.
|
|
173
|
+
*
|
|
174
|
+
* It is an exception rather than a `false` return because a boolean is silently
|
|
175
|
+
* ignorable, and an ignored signature check is the one failure mode a webhook
|
|
176
|
+
* receiver cannot afford.
|
|
177
|
+
*/
|
|
178
|
+
export declare class EnginiWebhookSignatureError extends EnginiError {
|
|
179
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -11,8 +11,16 @@ export class EnginiError extends Error {
|
|
|
11
11
|
/** Transport-level failure before a response was received. */
|
|
12
12
|
export class EnginiNetworkError extends EnginiError {
|
|
13
13
|
}
|
|
14
|
-
/** Any non-2xx API response with a parseable body. */
|
|
15
14
|
export class EnginiAPIError extends EnginiError {
|
|
15
|
+
errorCode;
|
|
16
|
+
details;
|
|
17
|
+
retryAfter;
|
|
18
|
+
constructor(message, options) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.errorCode = options?.errorCode;
|
|
21
|
+
this.details = options?.details ?? [];
|
|
22
|
+
this.retryAfter = options?.retryAfter;
|
|
23
|
+
}
|
|
16
24
|
}
|
|
17
25
|
/** 401 or 403 — token missing, invalid, expired, or lacking permission. */
|
|
18
26
|
export class EnginiAuthError extends EnginiAPIError {
|
|
@@ -23,7 +31,7 @@ export class EnginiNotFoundError extends EnginiAPIError {
|
|
|
23
31
|
/** 400 or 422 — request rejected; exposes field-level details (Phase 3). */
|
|
24
32
|
export class EnginiValidationError extends EnginiAPIError {
|
|
25
33
|
}
|
|
26
|
-
/** 429 — rate limited
|
|
34
|
+
/** 429 — rate limited. `retryAfter` carries the `Retry-After` header in seconds. */
|
|
27
35
|
export class EnginiRateLimitError extends EnginiAPIError {
|
|
28
36
|
}
|
|
29
37
|
/** 409 — the request conflicts with current resource state. */
|
|
@@ -76,3 +84,88 @@ export class EnginiToolExecutionError extends EnginiError {
|
|
|
76
84
|
this.historyId = opts.historyId ?? null;
|
|
77
85
|
}
|
|
78
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* No on-premise agent with that id is visible to this account. Also thrown when the id
|
|
89
|
+
* exists but belongs to another account, or is not an OPA agent at all — the API answers
|
|
90
|
+
* 404 for all three deliberately, so the endpoint cannot be used to probe which ids exist
|
|
91
|
+
* in other tenants.
|
|
92
|
+
*/
|
|
93
|
+
export class EnginiOpaAgentNotFoundError extends EnginiNotFoundError {
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The agent is not Online, so an operation needing a live round-trip cannot run
|
|
97
|
+
* (wire code `OPA_AGENT_OFFLINE`). Thrown by `logs`. A settings update does *not* throw
|
|
98
|
+
* this: it persists the change and reports `appliedToAgent: false` instead, so the caller
|
|
99
|
+
* knows the write landed but the agent has not seen it.
|
|
100
|
+
*/
|
|
101
|
+
export class EnginiOpaAgentOfflineError extends EnginiConflictError {
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* More than one on-premise-agent application exists; `create` needs an `applicationSlug`
|
|
105
|
+
* (wire code `OPA_APPLICATION_AMBIGUOUS`). `candidateSlugs` is the only place a caller can
|
|
106
|
+
* learn them: `/v1/applications` does not list OPA applications.
|
|
107
|
+
*/
|
|
108
|
+
export class EnginiOpaApplicationAmbiguousError extends EnginiConflictError {
|
|
109
|
+
candidateSlugs;
|
|
110
|
+
constructor(message, candidateSlugs, options) {
|
|
111
|
+
super(message, options);
|
|
112
|
+
this.candidateSlugs = candidateSlugs;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The agent did not answer a live round-trip within the server's bound (wire code
|
|
117
|
+
* `OPA_AGENT_TIMEOUT`, 504). Extends `EnginiServerError` rather than `EnginiTimeoutError`:
|
|
118
|
+
* that one is a *client-side* deadline outside the API-error tree, whereas this is a
|
|
119
|
+
* server-reported outcome carrying an `errorCode`.
|
|
120
|
+
*/
|
|
121
|
+
export class EnginiOpaAgentTimeoutError extends EnginiServerError {
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The agent was reached but reported a failure collecting or applying
|
|
125
|
+
* (wire code `OPA_AGENT_DISPATCH_FAILED`, 502).
|
|
126
|
+
*/
|
|
127
|
+
export class EnginiOpaAgentDispatchError extends EnginiServerError {
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The `since` cursor is older than the server's retained event window
|
|
131
|
+
* (wire code `SINCE_PRUNED`, 410).
|
|
132
|
+
*
|
|
133
|
+
* A hard stop for `triggers.subscribe`, never a silent restart: the whole point of
|
|
134
|
+
* `since` is that a gap in the stream is visible to the caller, so resuming from
|
|
135
|
+
* "now" would reintroduce exactly the invisible data loss the cursor exists to
|
|
136
|
+
* prevent. Recover by reading the missed events with `triggers.events.list` and
|
|
137
|
+
* subscribing again.
|
|
138
|
+
*
|
|
139
|
+
* 410 is the one trigger status with no row in `STATUS_TO_ERROR`; the retype
|
|
140
|
+
* happens on `errorCode` like the rest of this family.
|
|
141
|
+
*/
|
|
142
|
+
export class EnginiTriggerGapError extends EnginiAPIError {
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Engini could not establish the upstream subscription with the provider
|
|
146
|
+
* (wire code `TRIGGER_SUBSCRIBE_FAILED`, 502). The trigger exists but is not
|
|
147
|
+
* receiving events; the provider rejected or dropped the registration.
|
|
148
|
+
*/
|
|
149
|
+
export class EnginiTriggerSubscribeFailedError extends EnginiServerError {
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Too many concurrent SSE streams are open for this account (wire code
|
|
153
|
+
* `TRIGGER_STREAM_LIMIT_EXCEEDED`, 429). `retryAfter` carries the server's
|
|
154
|
+
* `Retry-After` in seconds, which `triggers.subscribe` honours before it retries.
|
|
155
|
+
*/
|
|
156
|
+
export class EnginiTriggerStreamLimitError extends EnginiRateLimitError {
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A delivered webhook failed signature verification.
|
|
160
|
+
*
|
|
161
|
+
* Thrown by `verifyWebhook` for every rejection — a bad or absent signature, a
|
|
162
|
+
* malformed header, an unknown scheme version, or a timestamp outside the replay
|
|
163
|
+
* tolerance. Deliberately outside the `EnginiAPIError` tree: nothing here came
|
|
164
|
+
* from an Engini API response.
|
|
165
|
+
*
|
|
166
|
+
* It is an exception rather than a `false` return because a boolean is silently
|
|
167
|
+
* ignorable, and an ignored signature check is the one failure mode a webhook
|
|
168
|
+
* receiver cannot afford.
|
|
169
|
+
*/
|
|
170
|
+
export class EnginiWebhookSignatureError extends EnginiError {
|
|
171
|
+
}
|
package/dist/http.d.ts
CHANGED
|
@@ -56,6 +56,23 @@ type Operation<O, R> = (options: O & {
|
|
|
56
56
|
error?: unknown;
|
|
57
57
|
response?: Response;
|
|
58
58
|
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Parse a `Retry-After` header into whole seconds, or `undefined`.
|
|
61
|
+
*
|
|
62
|
+
* RFC 9110 allows either a delay in seconds or an HTTP-date, and both are
|
|
63
|
+
* accepted here: a caller that backs off on the parsed value would otherwise
|
|
64
|
+
* silently fall back to its own guess against a server that answered in the date
|
|
65
|
+
* form. A past date clamps to 0 (retry now) rather than going negative.
|
|
66
|
+
*/
|
|
67
|
+
export declare function parseRetryAfter(value: string | null | undefined): number | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Shared helper: map an HTTP status to the appropriate error constructor.
|
|
70
|
+
*
|
|
71
|
+
* Exported because the triggers SSE stream never goes through a generated
|
|
72
|
+
* operation: it reads the error body off a raw `Response` and still has to land
|
|
73
|
+
* on exactly the same error classes as every other call.
|
|
74
|
+
*/
|
|
75
|
+
export declare function errorForStatus(status: number, error: unknown, headers?: Headers): Error;
|
|
59
76
|
/** Run a generated operation, map errors, return parsed success data. */
|
|
60
77
|
export declare function call<O extends object, R>(operation: Operation<O, R>, options: O): Promise<R>;
|
|
61
78
|
export {};
|
package/dist/http.js
CHANGED
|
@@ -95,11 +95,53 @@ export function buildClient(baseUrl, auth, companyToken, options = {}) {
|
|
|
95
95
|
});
|
|
96
96
|
return client;
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Parse a `Retry-After` header into whole seconds, or `undefined`.
|
|
100
|
+
*
|
|
101
|
+
* RFC 9110 allows either a delay in seconds or an HTTP-date, and both are
|
|
102
|
+
* accepted here: a caller that backs off on the parsed value would otherwise
|
|
103
|
+
* silently fall back to its own guess against a server that answered in the date
|
|
104
|
+
* form. A past date clamps to 0 (retry now) rather than going negative.
|
|
105
|
+
*/
|
|
106
|
+
export function parseRetryAfter(value) {
|
|
107
|
+
if (value === null || value === undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
const text = value.trim();
|
|
110
|
+
// RFC 9110's delay-seconds is `1*DIGIT` — unsigned — and Python's parser agrees, so
|
|
111
|
+
// both SDKs accept exactly this.
|
|
112
|
+
if (/^\d+$/.test(text))
|
|
113
|
+
return Number(text);
|
|
114
|
+
// Only try the date form on something that actually looks like one. `Date.parse` is
|
|
115
|
+
// lax enough to read "-5" as a date in 2001, which would silently turn a malformed
|
|
116
|
+
// header into a real (and wrong) delay; Python's `parsedate_to_datetime` rejects it.
|
|
117
|
+
if (!/^[A-Za-z]{3}/.test(text))
|
|
118
|
+
return undefined;
|
|
119
|
+
const when = Date.parse(text);
|
|
120
|
+
if (Number.isNaN(when))
|
|
121
|
+
return undefined;
|
|
122
|
+
// Rounded up, never down: honouring a `Retry-After` a fraction early is the one
|
|
123
|
+
// direction that defeats the point of the header.
|
|
124
|
+
return Math.max(0, Math.ceil((when - Date.now()) / 1000));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Shared helper: map an HTTP status to the appropriate error constructor.
|
|
128
|
+
*
|
|
129
|
+
* Exported because the triggers SSE stream never goes through a generated
|
|
130
|
+
* operation: it reads the error body off a raw `Response` and still has to land
|
|
131
|
+
* on exactly the same error classes as every other call.
|
|
132
|
+
*/
|
|
133
|
+
export function errorForStatus(status, error, headers) {
|
|
100
134
|
const message = errorMessage(error, status);
|
|
101
135
|
const Ctor = STATUS_TO_ERROR[status] ?? (status >= 500 ? EnginiServerError : EnginiAPIError);
|
|
102
|
-
|
|
136
|
+
// Carry the parsed body, not just its rendered message: callers need to tell
|
|
137
|
+
// apart conditions that share a status, and `details` is the only channel for
|
|
138
|
+
// structured hints (e.g. the candidate slugs on OPA_APPLICATION_AMBIGUOUS).
|
|
139
|
+
const body = (error ?? {});
|
|
140
|
+
return new Ctor(message, {
|
|
141
|
+
errorCode: typeof body.errorCode === "string" ? body.errorCode : undefined,
|
|
142
|
+
details: Array.isArray(body.details) ? body.details : [],
|
|
143
|
+
retryAfter: parseRetryAfter(headers?.get("retry-after")),
|
|
144
|
+
});
|
|
103
145
|
}
|
|
104
146
|
/** Run a generated operation, map errors, return parsed success data. */
|
|
105
147
|
export async function call(operation, options) {
|
|
@@ -111,7 +153,7 @@ export async function call(operation, options) {
|
|
|
111
153
|
// Check if the thrown value carries a response (e.g. hey-api throws on empty-body parse errors)
|
|
112
154
|
const errWithResponse = err;
|
|
113
155
|
if (errWithResponse.response instanceof Response) {
|
|
114
|
-
throw errorForStatus(errWithResponse.response.status, undefined);
|
|
156
|
+
throw errorForStatus(errWithResponse.response.status, undefined, errWithResponse.response.headers);
|
|
115
157
|
}
|
|
116
158
|
throw new EnginiNetworkError(err instanceof Error ? err.message : String(err));
|
|
117
159
|
}
|
|
@@ -123,7 +165,7 @@ export async function call(operation, options) {
|
|
|
123
165
|
if (status >= 200 && status < 300) {
|
|
124
166
|
return data;
|
|
125
167
|
}
|
|
126
|
-
throw errorForStatus(status, error);
|
|
168
|
+
throw errorForStatus(status, error, response.headers);
|
|
127
169
|
}
|
|
128
170
|
function errorMessage(error, status) {
|
|
129
171
|
if (error && typeof error === "object") {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,15 +5,18 @@ 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, } from "./errors.js";
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
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 { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, OpaResource, TriggersResource, ApplicationsResource, refreshFailed, verifyWebhook, } from "./resources/index.js";
|
|
11
|
+
export type { ToolsGetOptions, ToolsExecuteOptions, ApplicationsListOptions, TriggersClient, TriggerWebhookEvent, } from "./resources/index.js";
|
|
11
12
|
export { Toolset } from "./toolset.js";
|
|
12
13
|
export type { ConnectionBinding, ToolsetExecuteOptions } from "./toolset.js";
|
|
13
14
|
export { File } from "./files.js";
|
|
14
15
|
export type { FileWire } from "./files.js";
|
|
15
16
|
export type { ToolSchema, Filter, Sort, ToolExecuteResult, Application, ApplicationDetail, Connection, ConnectionDetail, ConnectionObject, WhoAmI, } from "./types.js";
|
|
16
17
|
export type { ToolsetConnectionDto, ToolsetConnectionRequest, ToolsetDto } from "@engini/client";
|
|
18
|
+
export type { OpaAgentListItem, OpaAgentDetail, OpaAgentSettings, OpaAgentTokenResponse, OpaAgentCreateResponse, OpaReleaseManifest, CreateOpaAgentRequest, UpdateOpaAgentRequest, } from "@engini/client";
|
|
19
|
+
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";
|
|
17
20
|
export type { McpServerPublicDto, McpServerConnectionDto, McpServerConnectionRequest, McpServerWorkflowDto, McpServerWorkflowRequest, McpAvailableToolDto, } from "@engini/client";
|
|
18
21
|
export type { Provider, ToolCall, ToolResultOptions } from "./providers/base.js";
|
|
19
22
|
export { OpenAIProvider } from "./providers/openai.js";
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ 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, } from "./errors.js";
|
|
6
|
-
export { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, ApplicationsResource, refreshFailed, } from "./resources/index.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 { ToolsResource, ConnectionsResource, ToolsetsResource, McpResource, OpaResource, TriggersResource, ApplicationsResource, refreshFailed, verifyWebhook, } from "./resources/index.js";
|
|
7
7
|
export { Toolset } from "./toolset.js";
|
|
8
8
|
export { File } from "./files.js";
|
|
9
9
|
export { OpenAIProvider } from "./providers/openai.js";
|
|
@@ -3,5 +3,9 @@ export type { ToolsGetOptions, ToolsExecuteOptions } from "./tools.js";
|
|
|
3
3
|
export { ConnectionsResource, refreshFailed } from "./connections.js";
|
|
4
4
|
export { ToolsetsResource } from "./toolsets.js";
|
|
5
5
|
export { McpResource } from "./mcp.js";
|
|
6
|
+
export { OpaResource } from "./opa.js";
|
|
7
|
+
export type { OpaClient } from "./opa.js";
|
|
8
|
+
export { TriggersResource, verifyWebhook } from "./triggers.js";
|
|
9
|
+
export type { TriggersClient, TriggerWebhookEvent } from "./triggers.js";
|
|
6
10
|
export { ApplicationsResource } from "./applications.js";
|
|
7
11
|
export type { ApplicationsListOptions } from "./applications.js";
|
package/dist/resources/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { ToolsResource } from "./tools.js";
|
|
|
2
2
|
export { ConnectionsResource, refreshFailed } from "./connections.js";
|
|
3
3
|
export { ToolsetsResource } from "./toolsets.js";
|
|
4
4
|
export { McpResource } from "./mcp.js";
|
|
5
|
+
export { OpaResource } from "./opa.js";
|
|
6
|
+
export { TriggersResource, verifyWebhook } from "./triggers.js";
|
|
5
7
|
export { ApplicationsResource } from "./applications.js";
|