@tangle-network/hub-sdk 0.19.3-develop.20260810030654.c70ddcb → 0.19.3

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/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
- function optString(value) {
56
- return typeof value === "string" ? value : "";
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, data) {
260
+ function toRunStreamEvent(eventType, raw) {
85
261
  if (eventType === "ping") return { type: "ping" };
86
- if (!isRecord$1(data)) return null;
262
+ if (!isRecord$1(raw)) return null;
87
263
  switch (eventType) {
88
- case "snapshot": return typeof data.id === "string" && typeof data.workflowId === "string" && typeof data.status === "string" && Array.isArray(data.actionResults) ? {
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: data
266
+ run: raw
91
267
  } : null;
92
- case "token": return typeof data.delta === "string" && typeof data.actionIndex === "number" ? {
268
+ case "token": return typeof raw.delta === "string" && typeof raw.actionIndex === "number" ? {
93
269
  type: "token",
94
- actionIndex: data.actionIndex,
95
- delta: data.delta,
96
- at: optString(data.at)
270
+ actionIndex: raw.actionIndex,
271
+ delta: raw.delta,
272
+ at: optString(raw.at)
97
273
  } : null;
98
- case "run.done": return isRunDoneStatus(data.status) ? {
274
+ case "run.done": return isRunDoneStatus(raw.status) ? {
99
275
  type: "run.done",
100
- status: data.status,
101
- error: typeof data.error === "string" ? data.error : null,
102
- ...typeof data.at === "string" ? { at: data.at } : {}
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 data.decisionId === "string" && data.decisionId.length > 0 ? {
280
+ case "run.waiting": return typeof raw.decisionId === "string" && raw.decisionId.length > 0 ? {
105
281
  type: "run.waiting",
106
- decisionId: data.decisionId,
107
- ...typeof data.at === "string" ? { at: data.at } : {}
282
+ decisionId: raw.decisionId,
283
+ ...typeof raw.at === "string" ? { at: raw.at } : {}
108
284
  } : null;
109
- case "action.started": return typeof data.index === "number" && typeof data.kind === "string" && typeof data.at === "string" ? {
285
+ case "action.started": return typeof raw.index === "number" && typeof raw.kind === "string" && typeof raw.at === "string" ? {
110
286
  type: "action.started",
111
- index: data.index,
112
- kind: data.kind,
113
- at: data.at
287
+ index: raw.index,
288
+ kind: raw.kind,
289
+ at: raw.at
114
290
  } : null;
115
- case "action.finished": return typeof data.index === "number" && typeof data.kind === "string" && isActionFinishedStatus(data.status) && typeof data.at === "string" ? {
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: data.index,
118
- kind: data.kind,
119
- status: data.status,
120
- at: data.at,
121
- ...typeof data.costUsd === "number" ? { costUsd: data.costUsd } : {},
122
- ...typeof data.error === "string" ? { error: data.error } : {}
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 data.actionIndex === "number" && typeof data.iterationIndex === "number" && typeof data.at === "string" ? {
300
+ case "iteration.started": return typeof raw.actionIndex === "number" && typeof raw.iterationIndex === "number" && typeof raw.at === "string" ? {
125
301
  type: "iteration.started",
126
- actionIndex: data.actionIndex,
127
- iterationIndex: data.iterationIndex,
128
- at: data.at,
129
- ...typeof data.model === "string" ? { model: data.model } : {}
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 data.actionIndex === "number" && typeof data.iterationIndex === "number" && isIterationStatus(data.status) && typeof data.at === "string" ? {
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: data.actionIndex,
134
- iterationIndex: data.iterationIndex,
135
- status: data.status,
136
- at: data.at,
137
- ...typeof data.outputPreview === "string" ? { outputPreview: data.outputPreview } : {},
138
- ...typeof data.inputTokens === "number" ? { inputTokens: data.inputTokens } : {},
139
- ...typeof data.outputTokens === "number" ? { outputTokens: data.outputTokens } : {},
140
- ...typeof data.costUsd === "number" ? { costUsd: data.costUsd } : {}
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(err) {
149
- return err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
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,34 +601,32 @@ 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
- method: "POST",
444
- body: JSON.stringify({
445
- query,
446
- provider: options.provider,
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
- async invoke(path, input, options = {}) {
463
- const execInit = this.buildExecInit(path, input, options.connectionId);
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) {
467
626
  if (!(error instanceof HubSdkError) || !requiresCapabilityToken(error)) throw error;
627
+ const approvalId = getApprovalId(error);
628
+ if (approvalId && options.approve !== true) throw error;
468
629
  if (options.approve) {
469
- const approvalId = getApprovalId(error);
470
630
  if (!approvalId) throw error;
471
631
  const approved = await this.request(`/v1/hub/approvals/${encodeURIComponent(approvalId)}/approve`, { method: "POST" });
472
632
  validateApprovedExecution(approved, path, options.connectionId);
@@ -484,15 +644,11 @@ var HubToolsClient = class {
484
644
  });
485
645
  }
486
646
  }
487
- const minted = await this.request("/v1/hub/tokens", {
488
- method: "POST",
489
- body: JSON.stringify({
490
- actionPath: path,
491
- connectionId: options.connectionId,
492
- provider: options.connectionId ? void 0 : path.split(".")[0]
493
- }),
494
- headers: { "Content-Type": "application/json" }
495
- });
647
+ const minted = await this.request("/v1/hub/tokens", jsonInit("POST", {
648
+ actionPath: path,
649
+ connectionId: options.connectionId,
650
+ provider: options.connectionId ? void 0 : path.split(".")[0]
651
+ }));
496
652
  return this.request("/v1/hub/exec", {
497
653
  ...execInit,
498
654
  headers: {
@@ -501,16 +657,13 @@ var HubToolsClient = class {
501
657
  }
502
658
  });
503
659
  }
504
- buildExecInit(path, input, connectionId) {
505
- return {
506
- method: "POST",
507
- body: JSON.stringify({
508
- path,
509
- input,
510
- connectionId
511
- }),
512
- headers: { "Content-Type": "application/json" }
513
- };
660
+ buildExecInit(path, raw, options) {
661
+ return jsonInit("POST", {
662
+ path,
663
+ input: raw,
664
+ connectionId: options.connectionId,
665
+ idempotencyKey: options.idempotencyKey
666
+ });
514
667
  }
515
668
  };
516
669
  function requiresCapabilityToken(error) {
@@ -548,11 +701,7 @@ var HubChannelsClient = class {
548
701
  return this.request("/v1/hub/channels", { method: "GET" });
549
702
  }
550
703
  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
- });
704
+ return this.request("/v1/hub/channels/email", jsonInit("POST", input));
556
705
  }
557
706
  async delete(channelId) {
558
707
  return this.request(`/v1/hub/channels/${encodeURIComponent(channelId)}`, { method: "DELETE" });
@@ -566,19 +715,17 @@ var HubEventSubscriptionsClient = class {
566
715
  return this.request("/v1/hub/event-subscriptions", { method: "GET" });
567
716
  }
568
717
  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
- });
718
+ return this.request("/v1/hub/event-subscriptions", jsonInit("POST", input));
574
719
  }
575
720
  async delete(subscriptionId) {
576
721
  return this.request(`/v1/hub/event-subscriptions/${encodeURIComponent(subscriptionId)}`, { method: "DELETE" });
577
722
  }
578
723
  };
579
724
  var HubConnectionsClient = class {
725
+ inboundWebhook;
580
726
  constructor(request) {
581
727
  this.request = request;
728
+ this.inboundWebhook = new HubInboundWebhooksClient(request);
582
729
  }
583
730
  async list() {
584
731
  return this.request("/v1/hub/connections", { method: "GET" });
@@ -590,39 +737,28 @@ var HubConnectionsClient = class {
590
737
  return this.request("/v1/hub/providers", { method: "GET" });
591
738
  }
592
739
  async start(provider, options = {}) {
593
- return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/start`, {
594
- method: "POST",
595
- body: JSON.stringify({
596
- returnUrl: options.returnUrl,
597
- cli: options.cli
598
- }),
599
- headers: { "Content-Type": "application/json" }
600
- });
740
+ return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/start`, jsonInit("POST", {
741
+ returnUrl: options.returnUrl,
742
+ cli: options.cli,
743
+ connectionParameters: options.connectionParameters
744
+ }));
601
745
  }
602
746
  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
- });
747
+ return this.request("/v1/hub/connections/whatsapp-business/embedded-signup/start", jsonInit("POST", { returnUrl: options.returnUrl }));
608
748
  }
609
749
  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
- });
750
+ return this.request("/v1/hub/connections/whatsapp-business/embedded-signup/complete", jsonInit("POST", input));
615
751
  }
616
752
  /** Connect a non-OAuth (api-key) connector by submitting the user's key.
617
753
  * The server validates the key with a live probe before persisting and
618
754
  * returns the created (or reconnected) connection — there is no redirect,
619
- * unlike `start`. */
620
- async connectApiKey(provider, apiKey) {
621
- return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/connect-key`, {
622
- method: "POST",
623
- body: JSON.stringify({ apiKey }),
624
- headers: { "Content-Type": "application/json" }
625
- });
755
+ * unlike `start`. Cloudbeds requires propertyId metadata and PriceLabs
756
+ * requires listing ID/PMS pairs; other providers have no metadata. */
757
+ async connectApiKey(provider, apiKey, metadata) {
758
+ return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/connect-key`, jsonInit("POST", {
759
+ apiKey,
760
+ ...metadata === void 0 ? {} : { metadata }
761
+ }));
626
762
  }
627
763
  async revoke(connectionId) {
628
764
  return this.request(`/v1/hub/connections/${encodeURIComponent(connectionId)}`, { method: "DELETE" });
@@ -650,11 +786,7 @@ var HubGithubAppClient = class {
650
786
  this.request = request;
651
787
  }
652
788
  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
- });
789
+ return this.request("/v1/hub/github-app/mint-installation-token", jsonInit("POST", input));
658
790
  }
659
791
  /** Every installation the caller may act through — their own and any org's
660
792
  * they were verified against. The management surface's read. */
@@ -729,11 +861,7 @@ var HubWorkflowsClient = class {
729
861
  return this.request(`/v1/workflows/${encodeURIComponent(id)}`, { method: "GET" });
730
862
  }
731
863
  async create(yaml) {
732
- return this.request("/v1/workflows", {
733
- method: "POST",
734
- body: JSON.stringify({ yaml }),
735
- headers: { "Content-Type": "application/json" }
736
- });
864
+ return this.request("/v1/workflows", jsonInit("POST", { yaml }));
737
865
  }
738
866
  /**
739
867
  * Replace the workflow's definition from YAML (recompiled server-side,
@@ -744,14 +872,10 @@ var HubWorkflowsClient = class {
744
872
  * concurrent modification, `NOT_FOUND` for an unknown/foreign id.
745
873
  */
746
874
  async update(id, yaml, opts = {}) {
747
- return this.request(`/v1/workflows/${encodeURIComponent(id)}`, {
748
- method: "PUT",
749
- body: JSON.stringify({
750
- yaml,
751
- ...opts.note !== void 0 ? { note: opts.note } : {}
752
- }),
753
- headers: { "Content-Type": "application/json" }
754
- });
875
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}`, jsonInit("PUT", {
876
+ yaml,
877
+ ...opts.note !== void 0 ? { note: opts.note } : {}
878
+ }));
755
879
  }
756
880
  async delete(id) {
757
881
  await this.request(`/v1/workflows/${encodeURIComponent(id)}`, { method: "DELETE" });
@@ -762,11 +886,7 @@ var HubWorkflowsClient = class {
762
886
  * via `update`, but it can still be paused/resumed here).
763
887
  */
764
888
  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
- });
889
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}`, jsonInit("PATCH", { enabled }));
770
890
  }
771
891
  /**
772
892
  * One page of run history, newest first. Pass the previous page's
@@ -794,9 +914,7 @@ var HubWorkflowsClient = class {
794
914
  async run(id, inputs, opts = {}) {
795
915
  const hasInputs = inputs !== void 0 && Object.keys(inputs).length > 0;
796
916
  return this.request(`/v1/workflows/${encodeURIComponent(id)}/run`, {
797
- method: "POST",
798
- body: JSON.stringify(hasInputs ? { inputs } : {}),
799
- headers: { "Content-Type": "application/json" },
917
+ ...jsonInit("POST", hasInputs ? { inputs } : {}),
800
918
  ...opts.signal ? { signal: opts.signal } : {}
801
919
  });
802
920
  }
@@ -975,11 +1093,7 @@ var HubWorkflowsClient = class {
975
1093
  * YAML no longer compiles, `CONFLICT` on a concurrent modification.
976
1094
  */
977
1095
  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
- });
1096
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}/rollback`, jsonInit("POST", { rev }));
983
1097
  }
984
1098
  /**
985
1099
  * Deterministic health stats over the workflow's last N terminal runs
@@ -1000,11 +1114,7 @@ var HubWorkflowsClient = class {
1000
1114
  * until an owner approves.
1001
1115
  */
1002
1116
  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
- });
1117
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}/proposals`, jsonInit("POST", input));
1008
1118
  }
1009
1119
  /**
1010
1120
  * Pending (proposed) and declined (rejected) revisions, newest first, with
@@ -1031,11 +1141,7 @@ var HubWorkflowsClient = class {
1031
1141
  * pending proposal.
1032
1142
  */
1033
1143
  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
- });
1144
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}/proposals/${encodeURIComponent(String(rev))}/reject`, jsonInit("POST", opts.reason !== void 0 ? { reason: opts.reason } : {}));
1039
1145
  }
1040
1146
  /**
1041
1147
  * Mint a fresh webhook hook token, retiring the current one immediately.
@@ -1111,29 +1217,24 @@ var HubWorkflowsClient = class {
1111
1217
  /**
1112
1218
  * Upsert a key; returns the entry with its NEW version (increments on every
1113
1219
  * write). Throws `HubSdkError(KV_VALUE_TOO_LARGE)` past the 64KiB value cap
1114
- * or `KV_KEY_LIMIT` past the per-workflow key cap.
1220
+ * or `KV_KEY_LIMIT` past the per-workflow key cap. `raw` is the caller's
1221
+ * value, stored and read back verbatim, so the client never gives it a shape.
1115
1222
  */
1116
- async putKv(id, key, value) {
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
- });
1223
+ async putKv(id, key, raw) {
1224
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}`, jsonInit("PUT", { value: raw }));
1122
1225
  }
1123
1226
  /**
1124
1227
  * Compare-and-swap: the write lands only when the stored version still
1125
1228
  * equals `expectedVersion`; otherwise `HubSdkError(KV_VERSION_CONFLICT)`
1126
- * (409) — re-read and retry. Creation is {@link putKv}'s job.
1229
+ * (409) — re-read and retry. Creation is {@link putKv}'s job. `raw` is the
1230
+ * caller's value, stored and read back verbatim, so the client never gives it
1231
+ * a shape.
1127
1232
  */
1128
- async casKv(id, key, expectedVersion, value) {
1129
- return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}/cas`, {
1130
- method: "POST",
1131
- body: JSON.stringify({
1132
- expectedVersion,
1133
- value
1134
- }),
1135
- headers: { "Content-Type": "application/json" }
1136
- });
1233
+ async casKv(id, key, expectedVersion, raw) {
1234
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}/kv/${encodeURIComponent(key)}/cas`, jsonInit("POST", {
1235
+ expectedVersion,
1236
+ value: raw
1237
+ }));
1137
1238
  }
1138
1239
  /** Delete a key; idempotent — `deleted` reports whether a row was removed. */
1139
1240
  async deleteKv(id, key) {
@@ -1153,11 +1254,7 @@ var HubWorkflowsClient = class {
1153
1254
  * (400); an unknown template id throws `NOT_FOUND`.
1154
1255
  */
1155
1256
  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
- });
1257
+ return this.request(`/v1/workflows/templates/${encodeURIComponent(templateId)}/instantiate`, jsonInit("POST", parameters ? { parameters } : {}));
1161
1258
  }
1162
1259
  /**
1163
1260
  * The caller's open decisions across all workflows — the always-available
@@ -1184,11 +1281,7 @@ var HubWorkflowsClient = class {
1184
1281
  * (409 — answered, timed out, or cancelled first).
1185
1282
  */
1186
1283
  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
- });
1284
+ return this.request(`/v1/workflows/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/decision/resolve`, jsonInit("POST", input));
1192
1285
  }
1193
1286
  /**
1194
1287
  * Dry-run a YAML definition against the platform compiler without saving it.
@@ -1201,14 +1294,10 @@ var HubWorkflowsClient = class {
1201
1294
  * the unconnected providers is the point.
1202
1295
  */
1203
1296
  async validate(yaml, opts = {}) {
1204
- return this.request("/v1/workflows/validate", {
1205
- method: "POST",
1206
- body: JSON.stringify({
1207
- yaml,
1208
- ...opts.structural ? { structural: true } : {}
1209
- }),
1210
- headers: { "Content-Type": "application/json" }
1211
- });
1297
+ return this.request("/v1/workflows/validate", jsonInit("POST", {
1298
+ yaml,
1299
+ ...opts.structural ? { structural: true } : {}
1300
+ }));
1212
1301
  }
1213
1302
  async schema() {
1214
1303
  return this.request("/v1/workflows/schema", { method: "GET" });
@@ -1472,6 +1561,6 @@ function requestFailure(code, status, error, headers) {
1472
1561
  };
1473
1562
  }
1474
1563
  //#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 };
1564
+ 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
1565
 
1477
1566
  //# sourceMappingURL=index.js.map