@tangle-network/hub-sdk 0.19.2-develop.20260808050113.9047fef → 0.19.2
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 +87 -6
- package/dist/index.d.ts +444 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +304 -216
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,178 @@
|
|
|
1
1
|
import { SSEChunkParser } from "@tangle-network/sdk-telemetry";
|
|
2
|
+
//#region src/json-init.ts
|
|
3
|
+
/** The init of a request whose body is JSON. Every client builds its bodies
|
|
4
|
+
* here, so the content type cannot drift from the encoding. */
|
|
5
|
+
function jsonInit(method, body) {
|
|
6
|
+
return {
|
|
7
|
+
method,
|
|
8
|
+
body: JSON.stringify(body),
|
|
9
|
+
headers: { "Content-Type": "application/json" }
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/allowances.ts
|
|
14
|
+
var HubAllowancesClient = class {
|
|
15
|
+
constructor(request) {
|
|
16
|
+
this.request = request;
|
|
17
|
+
}
|
|
18
|
+
async plan(meter) {
|
|
19
|
+
return (await this.request(this.path(meter), { method: "GET" })).plan;
|
|
20
|
+
}
|
|
21
|
+
async setPlan(meter, plan) {
|
|
22
|
+
return (await this.request(this.path(meter), this.body("PUT", plan))).plan;
|
|
23
|
+
}
|
|
24
|
+
/** Admit one turn or refuse it. Retrying the same `turnId` never counts twice. */
|
|
25
|
+
async admit(meter, input) {
|
|
26
|
+
return (await this.request(`${this.path(meter)}/turns`, this.body("POST", input))).allowance;
|
|
27
|
+
}
|
|
28
|
+
/** What the member's next turn would get, without counting anything. */
|
|
29
|
+
async status(meter, subject) {
|
|
30
|
+
const query = new URLSearchParams();
|
|
31
|
+
if (subject.role) query.set("role", subject.role);
|
|
32
|
+
if (subject.payer) query.set("payer", subject.payer);
|
|
33
|
+
if (subject.payerRole) query.set("payerRole", subject.payerRole);
|
|
34
|
+
const suffix = query.size ? `?${query}` : "";
|
|
35
|
+
return (await this.request(`${this.memberPath(meter, subject.member)}${suffix}`, { method: "GET" })).allowance;
|
|
36
|
+
}
|
|
37
|
+
/** Move a member to the paid allowance until `expiresAt` (the paid period's end). */
|
|
38
|
+
async grant(meter, member, input) {
|
|
39
|
+
return (await this.request(`${this.memberPath(meter, member)}/grant`, this.body("PUT", {
|
|
40
|
+
tier: "paid",
|
|
41
|
+
...input
|
|
42
|
+
}))).grant;
|
|
43
|
+
}
|
|
44
|
+
async revoke(meter, member) {
|
|
45
|
+
await this.request(`${this.memberPath(meter, member)}/grant`, { method: "DELETE" });
|
|
46
|
+
}
|
|
47
|
+
/** Turns per member and per line on one UTC day (default today). */
|
|
48
|
+
async usage(meter, day) {
|
|
49
|
+
const suffix = day ? `?day=${encodeURIComponent(day)}` : "";
|
|
50
|
+
return (await this.request(`${this.path(meter)}/usage${suffix}`, { method: "GET" })).usage;
|
|
51
|
+
}
|
|
52
|
+
path(meter) {
|
|
53
|
+
return `/v1/hub/allowances/${encodeURIComponent(meter)}`;
|
|
54
|
+
}
|
|
55
|
+
memberPath(meter, member) {
|
|
56
|
+
return `${this.path(meter)}/members/${encodeURIComponent(member)}`;
|
|
57
|
+
}
|
|
58
|
+
body(method, body) {
|
|
59
|
+
return jsonInit(method, body);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/apps.ts
|
|
64
|
+
function encodedId(id) {
|
|
65
|
+
if (typeof id !== "string" || !id || id.length > 256 || id === "." || id === "..") throw new Error("A bounded app or grant id is required");
|
|
66
|
+
return encodeURIComponent(id);
|
|
67
|
+
}
|
|
68
|
+
var HubAppsClient = class {
|
|
69
|
+
grants;
|
|
70
|
+
constructor(request) {
|
|
71
|
+
this.request = request;
|
|
72
|
+
this.grants = {
|
|
73
|
+
list: () => this.request("/v1/me/app-grants", { method: "GET" }),
|
|
74
|
+
revoke: async (grantId) => this.request(`/v1/me/app-grants/${encodedId(grantId)}/revoke`, { method: "POST" })
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
list() {
|
|
78
|
+
return this.request("/v1/apps", { method: "GET" });
|
|
79
|
+
}
|
|
80
|
+
/** The secret is returned only by creation; keep it in your server vault. */
|
|
81
|
+
create(input) {
|
|
82
|
+
return this.request("/v1/apps", jsonInit("POST", input));
|
|
83
|
+
}
|
|
84
|
+
/** Immutable association of two existing records with the same owner. */
|
|
85
|
+
async linkOAuthClient(appId, clientId) {
|
|
86
|
+
return this.request(`/v1/apps/${encodedId(appId)}/oidc-client`, jsonInit("POST", { clientId }));
|
|
87
|
+
}
|
|
88
|
+
async revoke(appId) {
|
|
89
|
+
return this.request(`/v1/apps/${encodedId(appId)}/revoke`, { method: "POST" });
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/inbound-webhooks.ts
|
|
94
|
+
var HubInboundWebhooksClient = class {
|
|
95
|
+
constructor(request) {
|
|
96
|
+
this.request = request;
|
|
97
|
+
}
|
|
98
|
+
async create(connectionId, options = {}) {
|
|
99
|
+
return this.request(this.path(connectionId), jsonInit("POST", options));
|
|
100
|
+
}
|
|
101
|
+
async get(connectionId) {
|
|
102
|
+
return this.request(this.path(connectionId), { method: "GET" });
|
|
103
|
+
}
|
|
104
|
+
/** Add one owned Linq WhatsApp number without rotating the webhook secret. */
|
|
105
|
+
async ensurePhoneNumber(connectionId, phoneNumberId) {
|
|
106
|
+
if (!phoneNumberId || phoneNumberId.length > 128 || !/^[\x21-\x7e]+$/.test(phoneNumberId)) throw new Error("A bounded phone-number id is required");
|
|
107
|
+
return this.request(`${this.path(connectionId)}/phone-numbers/ensure`, jsonInit("POST", { phoneNumberId }));
|
|
108
|
+
}
|
|
109
|
+
/** Remove event subscriptions first. This does not silently rotate a live URL. */
|
|
110
|
+
async delete(connectionId) {
|
|
111
|
+
return this.request(this.path(connectionId), { method: "DELETE" });
|
|
112
|
+
}
|
|
113
|
+
path(connectionId) {
|
|
114
|
+
if (!connectionId || connectionId.length > 256) throw new Error("A bounded connection id is required");
|
|
115
|
+
return `/v1/hub/connections/${encodeURIComponent(connectionId)}/inbound-webhook`;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/managed-numbers.ts
|
|
120
|
+
/** Administrative number operations through Hub's authenticated transport.
|
|
121
|
+
* A mutation is one attempt; an uncertain create reuses its quote and reference. */
|
|
122
|
+
var HubManagedNumbersClient = class {
|
|
123
|
+
constructor(request) {
|
|
124
|
+
this.request = request;
|
|
125
|
+
}
|
|
126
|
+
readiness() {
|
|
127
|
+
return this.request("/v1/hub/numbers/readiness", { method: "GET" });
|
|
128
|
+
}
|
|
129
|
+
/** One page of orders. Scope by `clientReference` to ask about one binding,
|
|
130
|
+
* and follow `nextCursor` for the rest; a page is never ownership evidence. */
|
|
131
|
+
list(query = {}) {
|
|
132
|
+
const params = new URLSearchParams();
|
|
133
|
+
if (query.clientReference !== void 0) params.set("clientReference", query.clientReference);
|
|
134
|
+
if (query.cursor !== void 0) params.set("cursor", query.cursor);
|
|
135
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
136
|
+
const search = params.toString();
|
|
137
|
+
return this.request(`/v1/hub/numbers${search ? `?${search}` : ""}`, { method: "GET" });
|
|
138
|
+
}
|
|
139
|
+
get(id) {
|
|
140
|
+
return this.request(this.path(id), { method: "GET" });
|
|
141
|
+
}
|
|
142
|
+
quote(input) {
|
|
143
|
+
return this.request("/v1/hub/numbers/quote", this.post(input));
|
|
144
|
+
}
|
|
145
|
+
/** `clientReference` and `transport`, when given, must match the signed
|
|
146
|
+
* quote or Hub refuses the purchase with a conflict. */
|
|
147
|
+
create(input) {
|
|
148
|
+
return this.request("/v1/hub/numbers", this.post(input));
|
|
149
|
+
}
|
|
150
|
+
/** Fences references so no order can take them again. Call it as the last
|
|
151
|
+
* step before retiring the resource they name: a purchase that races the
|
|
152
|
+
* retirement is then refused (`409 number_reference_fenced`) instead of
|
|
153
|
+
* binding a line to a resource that is gone. Refused with
|
|
154
|
+
* `409 number_reference_held` while a live order holds one of them; cancel
|
|
155
|
+
* it first. A cancelled order no longer holds its reference, so the fence
|
|
156
|
+
* succeeds as soon as `cancel` returns, whether or not its release is still
|
|
157
|
+
* pending. Repeating a fence is harmless. */
|
|
158
|
+
fence(input) {
|
|
159
|
+
return this.request("/v1/hub/numbers/fences", this.post(input));
|
|
160
|
+
}
|
|
161
|
+
advance(id) {
|
|
162
|
+
return this.request(`${this.path(id)}/advance`, this.post({}));
|
|
163
|
+
}
|
|
164
|
+
cancel(id) {
|
|
165
|
+
return this.request(`${this.path(id)}/cancel`, this.post({}));
|
|
166
|
+
}
|
|
167
|
+
path(id) {
|
|
168
|
+
if (!/^num_[a-f0-9]{36}$/.test(id)) throw new Error("Invalid managed number order id");
|
|
169
|
+
return `/v1/hub/numbers/${encodeURIComponent(id)}`;
|
|
170
|
+
}
|
|
171
|
+
post(body) {
|
|
172
|
+
return jsonInit("POST", body);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
//#endregion
|
|
2
176
|
//#region src/redaction.ts
|
|
3
177
|
const SECRET_KEY_PATTERN = /(api[_-]?key|authorization|capability[_-]?token|token|secret)/i;
|
|
4
178
|
const SECRET_VALUE_PATTERN = /\b(?:sk-tan[-_]|hubcap_|hct_|gh[pousr]_)[A-Za-z0-9_=-]+\b/g;
|
|
@@ -52,8 +226,10 @@ function isHubSuccessEnvelope(value) {
|
|
|
52
226
|
function isRecord$1(value) {
|
|
53
227
|
return typeof value === "object" && value !== null;
|
|
54
228
|
}
|
|
55
|
-
|
|
56
|
-
|
|
229
|
+
/** Read a wire field as a string, or "" when the server sent anything else.
|
|
230
|
+
* `raw` is that field straight off the parsed payload, before any check. */
|
|
231
|
+
function optString(raw) {
|
|
232
|
+
return typeof raw === "string" ? raw : "";
|
|
57
233
|
}
|
|
58
234
|
/** An agent iteration's terminal status (`iteration.ended`) — only ever
|
|
59
235
|
* succeeded/failed; an iteration is never guard-skipped. */
|
|
@@ -81,63 +257,63 @@ function isRunDoneStatus(value) {
|
|
|
81
257
|
* malformed `token` can never reach a consumer as `{ delta: undefined }`, and
|
|
82
258
|
* new server event kinds don't break older clients.
|
|
83
259
|
*/
|
|
84
|
-
function toRunStreamEvent(eventType,
|
|
260
|
+
function toRunStreamEvent(eventType, raw) {
|
|
85
261
|
if (eventType === "ping") return { type: "ping" };
|
|
86
|
-
if (!isRecord$1(
|
|
262
|
+
if (!isRecord$1(raw)) return null;
|
|
87
263
|
switch (eventType) {
|
|
88
|
-
case "snapshot": return typeof
|
|
264
|
+
case "snapshot": return typeof raw.id === "string" && typeof raw.workflowId === "string" && typeof raw.status === "string" && Array.isArray(raw.actionResults) ? {
|
|
89
265
|
type: "snapshot",
|
|
90
|
-
run:
|
|
266
|
+
run: raw
|
|
91
267
|
} : null;
|
|
92
|
-
case "token": return typeof
|
|
268
|
+
case "token": return typeof raw.delta === "string" && typeof raw.actionIndex === "number" ? {
|
|
93
269
|
type: "token",
|
|
94
|
-
actionIndex:
|
|
95
|
-
delta:
|
|
96
|
-
at: optString(
|
|
270
|
+
actionIndex: raw.actionIndex,
|
|
271
|
+
delta: raw.delta,
|
|
272
|
+
at: optString(raw.at)
|
|
97
273
|
} : null;
|
|
98
|
-
case "run.done": return isRunDoneStatus(
|
|
274
|
+
case "run.done": return isRunDoneStatus(raw.status) ? {
|
|
99
275
|
type: "run.done",
|
|
100
|
-
status:
|
|
101
|
-
error: typeof
|
|
102
|
-
...typeof
|
|
276
|
+
status: raw.status,
|
|
277
|
+
error: typeof raw.error === "string" ? raw.error : null,
|
|
278
|
+
...typeof raw.at === "string" ? { at: raw.at } : {}
|
|
103
279
|
} : null;
|
|
104
|
-
case "run.waiting": return typeof
|
|
280
|
+
case "run.waiting": return typeof raw.decisionId === "string" && raw.decisionId.length > 0 ? {
|
|
105
281
|
type: "run.waiting",
|
|
106
|
-
decisionId:
|
|
107
|
-
...typeof
|
|
282
|
+
decisionId: raw.decisionId,
|
|
283
|
+
...typeof raw.at === "string" ? { at: raw.at } : {}
|
|
108
284
|
} : null;
|
|
109
|
-
case "action.started": return typeof
|
|
285
|
+
case "action.started": return typeof raw.index === "number" && typeof raw.kind === "string" && typeof raw.at === "string" ? {
|
|
110
286
|
type: "action.started",
|
|
111
|
-
index:
|
|
112
|
-
kind:
|
|
113
|
-
at:
|
|
287
|
+
index: raw.index,
|
|
288
|
+
kind: raw.kind,
|
|
289
|
+
at: raw.at
|
|
114
290
|
} : null;
|
|
115
|
-
case "action.finished": return typeof
|
|
291
|
+
case "action.finished": return typeof raw.index === "number" && typeof raw.kind === "string" && isActionFinishedStatus(raw.status) && typeof raw.at === "string" ? {
|
|
116
292
|
type: "action.finished",
|
|
117
|
-
index:
|
|
118
|
-
kind:
|
|
119
|
-
status:
|
|
120
|
-
at:
|
|
121
|
-
...typeof
|
|
122
|
-
...typeof
|
|
293
|
+
index: raw.index,
|
|
294
|
+
kind: raw.kind,
|
|
295
|
+
status: raw.status,
|
|
296
|
+
at: raw.at,
|
|
297
|
+
...typeof raw.costUsd === "number" ? { costUsd: raw.costUsd } : {},
|
|
298
|
+
...typeof raw.error === "string" ? { error: raw.error } : {}
|
|
123
299
|
} : null;
|
|
124
|
-
case "iteration.started": return typeof
|
|
300
|
+
case "iteration.started": return typeof raw.actionIndex === "number" && typeof raw.iterationIndex === "number" && typeof raw.at === "string" ? {
|
|
125
301
|
type: "iteration.started",
|
|
126
|
-
actionIndex:
|
|
127
|
-
iterationIndex:
|
|
128
|
-
at:
|
|
129
|
-
...typeof
|
|
302
|
+
actionIndex: raw.actionIndex,
|
|
303
|
+
iterationIndex: raw.iterationIndex,
|
|
304
|
+
at: raw.at,
|
|
305
|
+
...typeof raw.model === "string" ? { model: raw.model } : {}
|
|
130
306
|
} : null;
|
|
131
|
-
case "iteration.ended": return typeof
|
|
307
|
+
case "iteration.ended": return typeof raw.actionIndex === "number" && typeof raw.iterationIndex === "number" && isIterationStatus(raw.status) && typeof raw.at === "string" ? {
|
|
132
308
|
type: "iteration.ended",
|
|
133
|
-
actionIndex:
|
|
134
|
-
iterationIndex:
|
|
135
|
-
status:
|
|
136
|
-
at:
|
|
137
|
-
...typeof
|
|
138
|
-
...typeof
|
|
139
|
-
...typeof
|
|
140
|
-
...typeof
|
|
309
|
+
actionIndex: raw.actionIndex,
|
|
310
|
+
iterationIndex: raw.iterationIndex,
|
|
311
|
+
status: raw.status,
|
|
312
|
+
at: raw.at,
|
|
313
|
+
...typeof raw.outputPreview === "string" ? { outputPreview: raw.outputPreview } : {},
|
|
314
|
+
...typeof raw.inputTokens === "number" ? { inputTokens: raw.inputTokens } : {},
|
|
315
|
+
...typeof raw.outputTokens === "number" ? { outputTokens: raw.outputTokens } : {},
|
|
316
|
+
...typeof raw.costUsd === "number" ? { costUsd: raw.costUsd } : {}
|
|
141
317
|
} : null;
|
|
142
318
|
default: return null;
|
|
143
319
|
}
|
|
@@ -145,8 +321,8 @@ function toRunStreamEvent(eventType, data) {
|
|
|
145
321
|
/** True for an aborted/timed-out fetch (or any abort). fetch rejects with the
|
|
146
322
|
* signal's reason — a DOMException named `AbortError` (caller) or `TimeoutError`
|
|
147
323
|
* (AbortSignal.timeout). */
|
|
148
|
-
function isAbortError(
|
|
149
|
-
return
|
|
324
|
+
function isAbortError(cause) {
|
|
325
|
+
return cause instanceof Error && (cause.name === "AbortError" || cause.name === "TimeoutError");
|
|
150
326
|
}
|
|
151
327
|
/** A signal that aborts when the caller's signal aborts OR `timeoutMs` elapses.
|
|
152
328
|
* Returns undefined when neither bound applies (no per-request abort needed). */
|
|
@@ -225,8 +401,11 @@ var HubClient = class HubClient {
|
|
|
225
401
|
fetch;
|
|
226
402
|
apiKey;
|
|
227
403
|
authHeaders;
|
|
404
|
+
allowances;
|
|
405
|
+
apps;
|
|
228
406
|
connections;
|
|
229
407
|
channels;
|
|
408
|
+
numbers;
|
|
230
409
|
eventSubscriptions;
|
|
231
410
|
permissions;
|
|
232
411
|
tokens;
|
|
@@ -240,6 +419,9 @@ var HubClient = class HubClient {
|
|
|
240
419
|
this.apiKey = options.apiKey;
|
|
241
420
|
this.authHeaders = options.authHeaders;
|
|
242
421
|
this.fetch = options.fetch ?? fetch.bind(globalThis);
|
|
422
|
+
this.allowances = new HubAllowancesClient((path, init) => this.request(path, init));
|
|
423
|
+
this.apps = new HubAppsClient((path, init) => this.request(path, init));
|
|
424
|
+
this.numbers = new HubManagedNumbersClient((path, init) => this.request(path, init));
|
|
243
425
|
this.connections = new HubConnectionsClient((path, init) => this.request(path, init));
|
|
244
426
|
this.channels = new HubChannelsClient((path, init) => this.request(path, init));
|
|
245
427
|
this.eventSubscriptions = new HubEventSubscriptionsClient((path, init) => this.request(path, init));
|
|
@@ -362,11 +544,7 @@ var HubTokensClient = class {
|
|
|
362
544
|
this.request = request;
|
|
363
545
|
}
|
|
364
546
|
async mint(options) {
|
|
365
|
-
return this.request("/v1/hub/tokens",
|
|
366
|
-
method: "POST",
|
|
367
|
-
body: JSON.stringify(options),
|
|
368
|
-
headers: { "Content-Type": "application/json" }
|
|
369
|
-
});
|
|
547
|
+
return this.request("/v1/hub/tokens", jsonInit("POST", options));
|
|
370
548
|
}
|
|
371
549
|
async list(options = {}) {
|
|
372
550
|
const searchParams = new URLSearchParams();
|
|
@@ -400,38 +578,22 @@ var HubPermissionsClient = class {
|
|
|
400
578
|
return this.request(`/v1/hub/policies?connectionId=${encodeURIComponent(connectionId)}`, { method: "GET" });
|
|
401
579
|
}
|
|
402
580
|
async set(input) {
|
|
403
|
-
return this.request("/v1/hub/policies",
|
|
404
|
-
method: "PUT",
|
|
405
|
-
body: JSON.stringify(input),
|
|
406
|
-
headers: { "Content-Type": "application/json" }
|
|
407
|
-
});
|
|
581
|
+
return this.request("/v1/hub/policies", jsonInit("PUT", input));
|
|
408
582
|
}
|
|
409
583
|
/** Reset an action to its default by deleting any stored override. */
|
|
410
584
|
async delete(input) {
|
|
411
|
-
return this.request("/v1/hub/policies",
|
|
412
|
-
method: "DELETE",
|
|
413
|
-
body: JSON.stringify(input),
|
|
414
|
-
headers: { "Content-Type": "application/json" }
|
|
415
|
-
});
|
|
585
|
+
return this.request("/v1/hub/policies", jsonInit("DELETE", input));
|
|
416
586
|
}
|
|
417
587
|
/** Bulk-allow every write action of a connection's provider. Reads are
|
|
418
588
|
* already allowed for sandbox agents; destructive actions stay `ask`.
|
|
419
589
|
* Idempotent: actions with an existing policy are left untouched. */
|
|
420
590
|
async allowWrites(connectionId) {
|
|
421
|
-
return this.request("/v1/hub/policies/allow-writes", {
|
|
422
|
-
method: "POST",
|
|
423
|
-
body: JSON.stringify({ connectionId }),
|
|
424
|
-
headers: { "Content-Type": "application/json" }
|
|
425
|
-
});
|
|
591
|
+
return this.request("/v1/hub/policies/allow-writes", jsonInit("POST", { connectionId }));
|
|
426
592
|
}
|
|
427
593
|
/** Inverse of `allowWrites`: delete only the rows it created for this
|
|
428
594
|
* connection. Manual per-action decisions are left intact. */
|
|
429
595
|
async revertWrites(connectionId) {
|
|
430
|
-
return this.request("/v1/hub/policies/revert-writes", {
|
|
431
|
-
method: "POST",
|
|
432
|
-
body: JSON.stringify({ connectionId }),
|
|
433
|
-
headers: { "Content-Type": "application/json" }
|
|
434
|
-
});
|
|
596
|
+
return this.request("/v1/hub/policies/revert-writes", jsonInit("POST", { connectionId }));
|
|
435
597
|
}
|
|
436
598
|
};
|
|
437
599
|
var HubToolsClient = class {
|
|
@@ -439,28 +601,25 @@ var HubToolsClient = class {
|
|
|
439
601
|
this.request = request;
|
|
440
602
|
}
|
|
441
603
|
async search(query, options = {}) {
|
|
442
|
-
return this.request("/v1/hub/tools/search", {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
limit: options.limit
|
|
448
|
-
}),
|
|
449
|
-
headers: { "Content-Type": "application/json" }
|
|
450
|
-
});
|
|
604
|
+
return this.request("/v1/hub/tools/search", jsonInit("POST", {
|
|
605
|
+
query,
|
|
606
|
+
provider: options.provider,
|
|
607
|
+
limit: options.limit
|
|
608
|
+
}));
|
|
451
609
|
}
|
|
452
610
|
async sources() {
|
|
453
611
|
return this.request("/v1/hub/tools/sources", { method: "GET" });
|
|
454
612
|
}
|
|
455
613
|
async describe(path) {
|
|
456
|
-
return this.request("/v1/hub/tools/describe", {
|
|
457
|
-
method: "POST",
|
|
458
|
-
body: JSON.stringify({ path }),
|
|
459
|
-
headers: { "Content-Type": "application/json" }
|
|
460
|
-
});
|
|
614
|
+
return this.request("/v1/hub/tools/describe", jsonInit("POST", { path }));
|
|
461
615
|
}
|
|
462
|
-
|
|
463
|
-
|
|
616
|
+
/**
|
|
617
|
+
* Run one hub tool. `raw` is the tool input: the SDK forwards it verbatim as
|
|
618
|
+
* the request body's `input`, and the server validates it against the tool's
|
|
619
|
+
* own schema, so the client never gives it a shape.
|
|
620
|
+
*/
|
|
621
|
+
async invoke(path, raw, options = {}) {
|
|
622
|
+
const execInit = this.buildExecInit(path, raw, options);
|
|
464
623
|
try {
|
|
465
624
|
return await this.request("/v1/hub/exec", execInit);
|
|
466
625
|
} catch (error) {
|
|
@@ -484,15 +643,11 @@ var HubToolsClient = class {
|
|
|
484
643
|
});
|
|
485
644
|
}
|
|
486
645
|
}
|
|
487
|
-
const minted = await this.request("/v1/hub/tokens", {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
provider: options.connectionId ? void 0 : path.split(".")[0]
|
|
493
|
-
}),
|
|
494
|
-
headers: { "Content-Type": "application/json" }
|
|
495
|
-
});
|
|
646
|
+
const minted = await this.request("/v1/hub/tokens", jsonInit("POST", {
|
|
647
|
+
actionPath: path,
|
|
648
|
+
connectionId: options.connectionId,
|
|
649
|
+
provider: options.connectionId ? void 0 : path.split(".")[0]
|
|
650
|
+
}));
|
|
496
651
|
return this.request("/v1/hub/exec", {
|
|
497
652
|
...execInit,
|
|
498
653
|
headers: {
|
|
@@ -501,16 +656,13 @@ var HubToolsClient = class {
|
|
|
501
656
|
}
|
|
502
657
|
});
|
|
503
658
|
}
|
|
504
|
-
buildExecInit(path,
|
|
505
|
-
return {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}),
|
|
512
|
-
headers: { "Content-Type": "application/json" }
|
|
513
|
-
};
|
|
659
|
+
buildExecInit(path, raw, options) {
|
|
660
|
+
return jsonInit("POST", {
|
|
661
|
+
path,
|
|
662
|
+
input: raw,
|
|
663
|
+
connectionId: options.connectionId,
|
|
664
|
+
idempotencyKey: options.idempotencyKey
|
|
665
|
+
});
|
|
514
666
|
}
|
|
515
667
|
};
|
|
516
668
|
function requiresCapabilityToken(error) {
|
|
@@ -548,11 +700,7 @@ var HubChannelsClient = class {
|
|
|
548
700
|
return this.request("/v1/hub/channels", { method: "GET" });
|
|
549
701
|
}
|
|
550
702
|
async createEmail(input = {}) {
|
|
551
|
-
return this.request("/v1/hub/channels/email",
|
|
552
|
-
method: "POST",
|
|
553
|
-
body: JSON.stringify(input),
|
|
554
|
-
headers: { "Content-Type": "application/json" }
|
|
555
|
-
});
|
|
703
|
+
return this.request("/v1/hub/channels/email", jsonInit("POST", input));
|
|
556
704
|
}
|
|
557
705
|
async delete(channelId) {
|
|
558
706
|
return this.request(`/v1/hub/channels/${encodeURIComponent(channelId)}`, { method: "DELETE" });
|
|
@@ -566,19 +714,17 @@ var HubEventSubscriptionsClient = class {
|
|
|
566
714
|
return this.request("/v1/hub/event-subscriptions", { method: "GET" });
|
|
567
715
|
}
|
|
568
716
|
async create(input) {
|
|
569
|
-
return this.request("/v1/hub/event-subscriptions",
|
|
570
|
-
method: "POST",
|
|
571
|
-
body: JSON.stringify(input),
|
|
572
|
-
headers: { "Content-Type": "application/json" }
|
|
573
|
-
});
|
|
717
|
+
return this.request("/v1/hub/event-subscriptions", jsonInit("POST", input));
|
|
574
718
|
}
|
|
575
719
|
async delete(subscriptionId) {
|
|
576
720
|
return this.request(`/v1/hub/event-subscriptions/${encodeURIComponent(subscriptionId)}`, { method: "DELETE" });
|
|
577
721
|
}
|
|
578
722
|
};
|
|
579
723
|
var HubConnectionsClient = class {
|
|
724
|
+
inboundWebhook;
|
|
580
725
|
constructor(request) {
|
|
581
726
|
this.request = request;
|
|
727
|
+
this.inboundWebhook = new HubInboundWebhooksClient(request);
|
|
582
728
|
}
|
|
583
729
|
async list() {
|
|
584
730
|
return this.request("/v1/hub/connections", { method: "GET" });
|
|
@@ -590,39 +736,28 @@ var HubConnectionsClient = class {
|
|
|
590
736
|
return this.request("/v1/hub/providers", { method: "GET" });
|
|
591
737
|
}
|
|
592
738
|
async start(provider, options = {}) {
|
|
593
|
-
return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/start`, {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}),
|
|
599
|
-
headers: { "Content-Type": "application/json" }
|
|
600
|
-
});
|
|
739
|
+
return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/start`, jsonInit("POST", {
|
|
740
|
+
returnUrl: options.returnUrl,
|
|
741
|
+
cli: options.cli,
|
|
742
|
+
connectionParameters: options.connectionParameters
|
|
743
|
+
}));
|
|
601
744
|
}
|
|
602
745
|
async startWhatsappEmbeddedSignup(options = {}) {
|
|
603
|
-
return this.request("/v1/hub/connections/whatsapp-business/embedded-signup/start", {
|
|
604
|
-
method: "POST",
|
|
605
|
-
body: JSON.stringify({ returnUrl: options.returnUrl }),
|
|
606
|
-
headers: { "Content-Type": "application/json" }
|
|
607
|
-
});
|
|
746
|
+
return this.request("/v1/hub/connections/whatsapp-business/embedded-signup/start", jsonInit("POST", { returnUrl: options.returnUrl }));
|
|
608
747
|
}
|
|
609
748
|
async completeWhatsappEmbeddedSignup(input) {
|
|
610
|
-
return this.request("/v1/hub/connections/whatsapp-business/embedded-signup/complete",
|
|
611
|
-
method: "POST",
|
|
612
|
-
body: JSON.stringify(input),
|
|
613
|
-
headers: { "Content-Type": "application/json" }
|
|
614
|
-
});
|
|
749
|
+
return this.request("/v1/hub/connections/whatsapp-business/embedded-signup/complete", jsonInit("POST", input));
|
|
615
750
|
}
|
|
616
751
|
/** Connect a non-OAuth (api-key) connector by submitting the user's key.
|
|
617
752
|
* The server validates the key with a live probe before persisting and
|
|
618
753
|
* returns the created (or reconnected) connection — there is no redirect,
|
|
619
|
-
* unlike `start`.
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
});
|
|
754
|
+
* unlike `start`. Cloudbeds requires propertyId metadata and PriceLabs
|
|
755
|
+
* requires listing ID/PMS pairs; other providers have no metadata. */
|
|
756
|
+
async connectApiKey(provider, apiKey, metadata) {
|
|
757
|
+
return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/connect-key`, jsonInit("POST", {
|
|
758
|
+
apiKey,
|
|
759
|
+
...metadata === void 0 ? {} : { metadata }
|
|
760
|
+
}));
|
|
626
761
|
}
|
|
627
762
|
async revoke(connectionId) {
|
|
628
763
|
return this.request(`/v1/hub/connections/${encodeURIComponent(connectionId)}`, { method: "DELETE" });
|
|
@@ -650,11 +785,7 @@ var HubGithubAppClient = class {
|
|
|
650
785
|
this.request = request;
|
|
651
786
|
}
|
|
652
787
|
async mintInstallationToken(input) {
|
|
653
|
-
return this.request("/v1/hub/github-app/mint-installation-token",
|
|
654
|
-
method: "POST",
|
|
655
|
-
body: JSON.stringify(input),
|
|
656
|
-
headers: { "Content-Type": "application/json" }
|
|
657
|
-
});
|
|
788
|
+
return this.request("/v1/hub/github-app/mint-installation-token", jsonInit("POST", input));
|
|
658
789
|
}
|
|
659
790
|
/** Every installation the caller may act through — their own and any org's
|
|
660
791
|
* they were verified against. The management surface's read. */
|
|
@@ -729,11 +860,7 @@ var HubWorkflowsClient = class {
|
|
|
729
860
|
return this.request(`/v1/workflows/${encodeURIComponent(id)}`, { method: "GET" });
|
|
730
861
|
}
|
|
731
862
|
async create(yaml) {
|
|
732
|
-
return this.request("/v1/workflows", {
|
|
733
|
-
method: "POST",
|
|
734
|
-
body: JSON.stringify({ yaml }),
|
|
735
|
-
headers: { "Content-Type": "application/json" }
|
|
736
|
-
});
|
|
863
|
+
return this.request("/v1/workflows", jsonInit("POST", { yaml }));
|
|
737
864
|
}
|
|
738
865
|
/**
|
|
739
866
|
* Replace the workflow's definition from YAML (recompiled server-side,
|
|
@@ -744,14 +871,10 @@ var HubWorkflowsClient = class {
|
|
|
744
871
|
* concurrent modification, `NOT_FOUND` for an unknown/foreign id.
|
|
745
872
|
*/
|
|
746
873
|
async update(id, yaml, opts = {}) {
|
|
747
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}`, {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
...opts.note !== void 0 ? { note: opts.note } : {}
|
|
752
|
-
}),
|
|
753
|
-
headers: { "Content-Type": "application/json" }
|
|
754
|
-
});
|
|
874
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}`, jsonInit("PUT", {
|
|
875
|
+
yaml,
|
|
876
|
+
...opts.note !== void 0 ? { note: opts.note } : {}
|
|
877
|
+
}));
|
|
755
878
|
}
|
|
756
879
|
async delete(id) {
|
|
757
880
|
await this.request(`/v1/workflows/${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
@@ -762,11 +885,7 @@ var HubWorkflowsClient = class {
|
|
|
762
885
|
* via `update`, but it can still be paused/resumed here).
|
|
763
886
|
*/
|
|
764
887
|
async setEnabled(id, enabled) {
|
|
765
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}`, {
|
|
766
|
-
method: "PATCH",
|
|
767
|
-
body: JSON.stringify({ enabled }),
|
|
768
|
-
headers: { "Content-Type": "application/json" }
|
|
769
|
-
});
|
|
888
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}`, jsonInit("PATCH", { enabled }));
|
|
770
889
|
}
|
|
771
890
|
/**
|
|
772
891
|
* One page of run history, newest first. Pass the previous page's
|
|
@@ -794,9 +913,7 @@ var HubWorkflowsClient = class {
|
|
|
794
913
|
async run(id, inputs, opts = {}) {
|
|
795
914
|
const hasInputs = inputs !== void 0 && Object.keys(inputs).length > 0;
|
|
796
915
|
return this.request(`/v1/workflows/${encodeURIComponent(id)}/run`, {
|
|
797
|
-
|
|
798
|
-
body: JSON.stringify(hasInputs ? { inputs } : {}),
|
|
799
|
-
headers: { "Content-Type": "application/json" },
|
|
916
|
+
...jsonInit("POST", hasInputs ? { inputs } : {}),
|
|
800
917
|
...opts.signal ? { signal: opts.signal } : {}
|
|
801
918
|
});
|
|
802
919
|
}
|
|
@@ -975,11 +1092,7 @@ var HubWorkflowsClient = class {
|
|
|
975
1092
|
* YAML no longer compiles, `CONFLICT` on a concurrent modification.
|
|
976
1093
|
*/
|
|
977
1094
|
async rollback(id, rev) {
|
|
978
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}/rollback`, {
|
|
979
|
-
method: "POST",
|
|
980
|
-
body: JSON.stringify({ rev }),
|
|
981
|
-
headers: { "Content-Type": "application/json" }
|
|
982
|
-
});
|
|
1095
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}/rollback`, jsonInit("POST", { rev }));
|
|
983
1096
|
}
|
|
984
1097
|
/**
|
|
985
1098
|
* Deterministic health stats over the workflow's last N terminal runs
|
|
@@ -1000,11 +1113,7 @@ var HubWorkflowsClient = class {
|
|
|
1000
1113
|
* until an owner approves.
|
|
1001
1114
|
*/
|
|
1002
1115
|
async propose(id, input) {
|
|
1003
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}/proposals`,
|
|
1004
|
-
method: "POST",
|
|
1005
|
-
body: JSON.stringify(input),
|
|
1006
|
-
headers: { "Content-Type": "application/json" }
|
|
1007
|
-
});
|
|
1116
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}/proposals`, jsonInit("POST", input));
|
|
1008
1117
|
}
|
|
1009
1118
|
/**
|
|
1010
1119
|
* Pending (proposed) and declined (rejected) revisions, newest first, with
|
|
@@ -1031,11 +1140,7 @@ var HubWorkflowsClient = class {
|
|
|
1031
1140
|
* pending proposal.
|
|
1032
1141
|
*/
|
|
1033
1142
|
async rejectProposal(id, rev, opts = {}) {
|
|
1034
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}/proposals/${encodeURIComponent(String(rev))}/reject`, {
|
|
1035
|
-
method: "POST",
|
|
1036
|
-
body: JSON.stringify(opts.reason !== void 0 ? { reason: opts.reason } : {}),
|
|
1037
|
-
headers: { "Content-Type": "application/json" }
|
|
1038
|
-
});
|
|
1143
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}/proposals/${encodeURIComponent(String(rev))}/reject`, jsonInit("POST", opts.reason !== void 0 ? { reason: opts.reason } : {}));
|
|
1039
1144
|
}
|
|
1040
1145
|
/**
|
|
1041
1146
|
* Mint a fresh webhook hook token, retiring the current one immediately.
|
|
@@ -1111,29 +1216,24 @@ var HubWorkflowsClient = class {
|
|
|
1111
1216
|
/**
|
|
1112
1217
|
* Upsert a key; returns the entry with its NEW version (increments on every
|
|
1113
1218
|
* write). Throws `HubSdkError(KV_VALUE_TOO_LARGE)` past the 64KiB value cap
|
|
1114
|
-
* or `KV_KEY_LIMIT` past the per-workflow key cap.
|
|
1219
|
+
* or `KV_KEY_LIMIT` past the per-workflow key cap. `raw` is the caller's
|
|
1220
|
+
* value, stored and read back verbatim, so the client never gives it a shape.
|
|
1115
1221
|
*/
|
|
1116
|
-
async putKv(id, key,
|
|
1117
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}`, {
|
|
1118
|
-
method: "PUT",
|
|
1119
|
-
body: JSON.stringify({ value }),
|
|
1120
|
-
headers: { "Content-Type": "application/json" }
|
|
1121
|
-
});
|
|
1222
|
+
async putKv(id, key, raw) {
|
|
1223
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}`, jsonInit("PUT", { value: raw }));
|
|
1122
1224
|
}
|
|
1123
1225
|
/**
|
|
1124
1226
|
* Compare-and-swap: the write lands only when the stored version still
|
|
1125
1227
|
* equals `expectedVersion`; otherwise `HubSdkError(KV_VERSION_CONFLICT)`
|
|
1126
|
-
* (409) — re-read and retry. Creation is {@link putKv}'s job.
|
|
1228
|
+
* (409) — re-read and retry. Creation is {@link putKv}'s job. `raw` is the
|
|
1229
|
+
* caller's value, stored and read back verbatim, so the client never gives it
|
|
1230
|
+
* a shape.
|
|
1127
1231
|
*/
|
|
1128
|
-
async casKv(id, key, expectedVersion,
|
|
1129
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}/cas`, {
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
value
|
|
1134
|
-
}),
|
|
1135
|
-
headers: { "Content-Type": "application/json" }
|
|
1136
|
-
});
|
|
1232
|
+
async casKv(id, key, expectedVersion, raw) {
|
|
1233
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}/cas`, jsonInit("POST", {
|
|
1234
|
+
expectedVersion,
|
|
1235
|
+
value: raw
|
|
1236
|
+
}));
|
|
1137
1237
|
}
|
|
1138
1238
|
/** Delete a key; idempotent — `deleted` reports whether a row was removed. */
|
|
1139
1239
|
async deleteKv(id, key) {
|
|
@@ -1153,11 +1253,7 @@ var HubWorkflowsClient = class {
|
|
|
1153
1253
|
* (400); an unknown template id throws `NOT_FOUND`.
|
|
1154
1254
|
*/
|
|
1155
1255
|
async instantiateTemplate(templateId, parameters) {
|
|
1156
|
-
return this.request(`/v1/workflows/templates/${encodeURIComponent(templateId)}/instantiate`, {
|
|
1157
|
-
method: "POST",
|
|
1158
|
-
body: JSON.stringify(parameters ? { parameters } : {}),
|
|
1159
|
-
headers: { "Content-Type": "application/json" }
|
|
1160
|
-
});
|
|
1256
|
+
return this.request(`/v1/workflows/templates/${encodeURIComponent(templateId)}/instantiate`, jsonInit("POST", parameters ? { parameters } : {}));
|
|
1161
1257
|
}
|
|
1162
1258
|
/**
|
|
1163
1259
|
* The caller's open decisions across all workflows — the always-available
|
|
@@ -1184,11 +1280,7 @@ var HubWorkflowsClient = class {
|
|
|
1184
1280
|
* (409 — answered, timed out, or cancelled first).
|
|
1185
1281
|
*/
|
|
1186
1282
|
async resolveRunDecision(id, runId, input) {
|
|
1187
|
-
return this.request(`/v1/workflows/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/decision/resolve`,
|
|
1188
|
-
method: "POST",
|
|
1189
|
-
body: JSON.stringify(input),
|
|
1190
|
-
headers: { "Content-Type": "application/json" }
|
|
1191
|
-
});
|
|
1283
|
+
return this.request(`/v1/workflows/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/decision/resolve`, jsonInit("POST", input));
|
|
1192
1284
|
}
|
|
1193
1285
|
/**
|
|
1194
1286
|
* Dry-run a YAML definition against the platform compiler without saving it.
|
|
@@ -1201,14 +1293,10 @@ var HubWorkflowsClient = class {
|
|
|
1201
1293
|
* the unconnected providers is the point.
|
|
1202
1294
|
*/
|
|
1203
1295
|
async validate(yaml, opts = {}) {
|
|
1204
|
-
return this.request("/v1/workflows/validate", {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
...opts.structural ? { structural: true } : {}
|
|
1209
|
-
}),
|
|
1210
|
-
headers: { "Content-Type": "application/json" }
|
|
1211
|
-
});
|
|
1296
|
+
return this.request("/v1/workflows/validate", jsonInit("POST", {
|
|
1297
|
+
yaml,
|
|
1298
|
+
...opts.structural ? { structural: true } : {}
|
|
1299
|
+
}));
|
|
1212
1300
|
}
|
|
1213
1301
|
async schema() {
|
|
1214
1302
|
return this.request("/v1/workflows/schema", { method: "GET" });
|
|
@@ -1472,6 +1560,6 @@ function requestFailure(code, status, error, headers) {
|
|
|
1472
1560
|
};
|
|
1473
1561
|
}
|
|
1474
1562
|
//#endregion
|
|
1475
|
-
export { HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR, HUB_URL_ENV_VAR, HubApprovalsClient, HubAuditClient, HubChannelsClient, HubClient, HubConnectionsClient, HubEventDeliveryError, HubEventSubscriptionsClient, HubGithubAppClient, HubPermissionsClient, HubSdkError, HubTokensClient, HubToolsClient, HubWorkflowsClient, authenticateHubEventRequest, deriveHubEventCallbackSecret, parseHubEventDelivery, redactHubValue, resolveHubAuth, resolveHubBaseUrl, verifyHubEventSignature };
|
|
1563
|
+
export { HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR, HUB_URL_ENV_VAR, HubAllowancesClient, HubApprovalsClient, HubAppsClient, HubAuditClient, HubChannelsClient, HubClient, HubConnectionsClient, HubEventDeliveryError, HubEventSubscriptionsClient, HubGithubAppClient, HubInboundWebhooksClient, HubManagedNumbersClient, HubPermissionsClient, HubSdkError, HubTokensClient, HubToolsClient, HubWorkflowsClient, authenticateHubEventRequest, deriveHubEventCallbackSecret, parseHubEventDelivery, redactHubValue, resolveHubAuth, resolveHubBaseUrl, verifyHubEventSignature };
|
|
1476
1564
|
|
|
1477
1565
|
//# sourceMappingURL=index.js.map
|