@tangle-network/hub-sdk 0.2.0 → 0.2.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 +140 -0
- package/dist/index.d.ts +148 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# @tangle-network/hub-sdk
|
|
2
|
+
|
|
3
|
+
Typed SDK for the Tangle Hub `/v1/hub/*` surface. Status, connections, tools
|
|
4
|
+
discovery and invocation, capability tokens, policies, approvals, audit.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @tangle-network/hub-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { HubClient } from "@tangle-network/hub-sdk";
|
|
16
|
+
|
|
17
|
+
const hub = HubClient.fromEnv();
|
|
18
|
+
const { principal, connections } = await hub.status();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`HubClient.fromEnv()` reads everything it needs from environment variables.
|
|
22
|
+
SaaS vs on-prem flips via env only — there is no per-client default URL.
|
|
23
|
+
|
|
24
|
+
## Environment variables
|
|
25
|
+
|
|
26
|
+
| Variable | Required | Meaning |
|
|
27
|
+
| ------------------------------ | -------- | --------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `TANGLE_HUB_URL` | Yes | Hub root URL. Either the platform root (`https://api.tangle.tools`) or the full Hub URL including `/v1/hub` — both are accepted; the SDK normalizes. |
|
|
29
|
+
| `TANGLE_API_KEY` | One of | Long-lived API key (Bearer). User / API key principal. |
|
|
30
|
+
| `TANGLE_HUB_CAPABILITY_TOKEN` | One of | Short-lived capability token (Bearer). Sandbox-runtime principal. Auto-minted server-side per action. |
|
|
31
|
+
|
|
32
|
+
The two auth credentials are mutually exclusive — set exactly one. This
|
|
33
|
+
mirrors the platform-api `hubSandboxEnvironmentSchema` rule
|
|
34
|
+
(`exactly-one-api-key-or-capability-token`).
|
|
35
|
+
|
|
36
|
+
### Examples
|
|
37
|
+
|
|
38
|
+
SaaS:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
export TANGLE_HUB_URL=https://api.tangle.tools
|
|
42
|
+
export TANGLE_API_KEY=sk-tan-...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
On-prem:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
export TANGLE_HUB_URL=https://hub.acme.internal
|
|
49
|
+
export TANGLE_API_KEY=sk-tan-...
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Inside a sandbox (capability-token principal):
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
export TANGLE_HUB_URL=https://api.tangle.tools/v1/hub
|
|
56
|
+
export TANGLE_HUB_CAPABILITY_TOKEN=hubcap_...
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Fail-loud configuration
|
|
60
|
+
|
|
61
|
+
`HubClient.fromEnv()` (and the standalone resolvers `resolveHubBaseUrl()` /
|
|
62
|
+
`resolveHubAuth()`) **never default**. Missing or malformed configuration
|
|
63
|
+
throws `HubSdkError` synchronously, before any request is issued:
|
|
64
|
+
|
|
65
|
+
| Code | Cause |
|
|
66
|
+
| --------------------- | -------------------------------------------------------------------------------- |
|
|
67
|
+
| `HUB_CONFIG_MISSING` | `TANGLE_HUB_URL` unset/empty, **or** neither auth credential is set. |
|
|
68
|
+
| `HUB_CONFIG_INVALID` | `TANGLE_HUB_URL` is not a valid URL, **or** both auth credentials are set. |
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
try {
|
|
72
|
+
const hub = HubClient.fromEnv();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error instanceof HubSdkError && error.code === "HUB_CONFIG_MISSING") {
|
|
75
|
+
// Surface the missing env var to the operator. Do not retry, do not default.
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This matches the repository's "No fallbacks. Fail loud." doctrine: required
|
|
82
|
+
config has no silent default.
|
|
83
|
+
|
|
84
|
+
## Bypassing env auth resolve
|
|
85
|
+
|
|
86
|
+
Pass `apiKey` or `authHeaders` explicitly to skip the auth-env-var check
|
|
87
|
+
(useful when credentials come from a vault, OIDC exchange, or a custom
|
|
88
|
+
session token). `TANGLE_HUB_URL` is still required.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const hub = HubClient.fromEnv({
|
|
92
|
+
apiKey: await vault.read("hub/api-key"),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const hub = HubClient.fromEnv({
|
|
96
|
+
authHeaders: async () => ({ Authorization: `Bearer ${await sessionToken()}` }),
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Constructing without env vars
|
|
101
|
+
|
|
102
|
+
`new HubClient({...})` remains supported for callers that resolve config
|
|
103
|
+
themselves (CLI flags, web app config, tests). `fromEnv` is sugar with a
|
|
104
|
+
fail-loud contract on top.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const hub = new HubClient({
|
|
108
|
+
baseUrl: "https://api.tangle.tools",
|
|
109
|
+
apiKey: "sk-tan-...",
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Browsers, Workers, edge runtimes
|
|
114
|
+
|
|
115
|
+
`fromEnv()` reads `globalThis.process?.env` — undefined in browsers and many
|
|
116
|
+
edge runtimes. Pass an explicit `env` map there:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const hub = HubClient.fromEnv({
|
|
120
|
+
env: {
|
|
121
|
+
TANGLE_HUB_URL: import.meta.env.VITE_TANGLE_HUB_URL,
|
|
122
|
+
TANGLE_API_KEY: await session.apiKey(),
|
|
123
|
+
},
|
|
124
|
+
fetch: globalThis.fetch,
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Exports
|
|
129
|
+
|
|
130
|
+
- `HubClient`, `HubClient.fromEnv(options?)`
|
|
131
|
+
- `HubConnectionsClient`, `HubPermissionsClient`, `HubTokensClient`,
|
|
132
|
+
`HubToolsClient`, `HubApprovalsClient`, `HubAuditClient`
|
|
133
|
+
- `HubSdkError` — typed `code: HubErrorCode`, redacted `details`, optional
|
|
134
|
+
HTTP `status`
|
|
135
|
+
- `HUB_URL_ENV_VAR`, `HUB_API_KEY_ENV_VAR`, `HUB_CAPABILITY_TOKEN_ENV_VAR` —
|
|
136
|
+
string constants for the env-var names (mirrored by the platform-api
|
|
137
|
+
`hub-sandbox-contract.ts` `z.literal(...)`)
|
|
138
|
+
- `resolveHubBaseUrl(env?)`, `resolveHubAuth(env?)` — standalone resolvers
|
|
139
|
+
with the same fail-loud contract as `fromEnv`
|
|
140
|
+
- All request/response types from the `/v1/hub/*` contract
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface HubErrorBody {
|
|
|
14
14
|
message: string;
|
|
15
15
|
details?: unknown;
|
|
16
16
|
}
|
|
17
|
-
type HubErrorCode = "HUB_UNAUTHENTICATED" | "HUB_FORBIDDEN" | "HUB_INVALID_INPUT" | "HUB_PROVIDER_MISSING" | "HUB_CONNECTION_MISSING" | "HUB_CONNECTION_REVOKED" | "HUB_TOKEN_EXPIRED" | "HUB_TOKEN_REPLAYED" | "HUB_TOKEN_REVOKED" | "HUB_TOKEN_ACTION_MISMATCH" | "HUB_POLICY_DENIED" | "HUB_APPROVAL_REQUIRED" | "HUB_EXECUTOR_FAILURE" | "HUB_PROVIDER_FAILURE" | "HUB_CONFIG_MISSING" | "HUB_NOT_FOUND" | "HUB_NOT_IMPLEMENTED";
|
|
17
|
+
type HubErrorCode = "HUB_UNAUTHENTICATED" | "HUB_FORBIDDEN" | "HUB_INVALID_INPUT" | "HUB_PROVIDER_MISSING" | "HUB_CONNECTION_MISSING" | "HUB_CONNECTION_REVOKED" | "HUB_TOKEN_EXPIRED" | "HUB_TOKEN_REPLAYED" | "HUB_TOKEN_REVOKED" | "HUB_TOKEN_ACTION_MISMATCH" | "HUB_POLICY_DENIED" | "HUB_APPROVAL_REQUIRED" | "HUB_EXECUTOR_FAILURE" | "HUB_PROVIDER_FAILURE" | "HUB_CONFIG_MISSING" | "HUB_CONFIG_INVALID" | "HUB_NOT_FOUND" | "HUB_NOT_IMPLEMENTED";
|
|
18
18
|
interface HubStatusResponse {
|
|
19
19
|
contract: unknown;
|
|
20
20
|
principal: HubPrincipal;
|
|
@@ -84,6 +84,23 @@ interface HubConnectionDeleteRequest {
|
|
|
84
84
|
interface HubConnectionDeleteResponse {
|
|
85
85
|
connection: HubConnection;
|
|
86
86
|
}
|
|
87
|
+
interface HubConnectionHealthRequest {
|
|
88
|
+
connectionId: string;
|
|
89
|
+
}
|
|
90
|
+
type HubConnectionHealthStatus = "healthy" | "reconnect_required" | "unhealthy" | "rate_limited";
|
|
91
|
+
interface HubConnectionHealthError {
|
|
92
|
+
code: string;
|
|
93
|
+
message: string;
|
|
94
|
+
}
|
|
95
|
+
interface HubConnectionHealthInfo {
|
|
96
|
+
status: HubConnectionHealthStatus;
|
|
97
|
+
checkedAt: string;
|
|
98
|
+
error?: HubConnectionHealthError;
|
|
99
|
+
}
|
|
100
|
+
interface HubConnectionHealthResponse {
|
|
101
|
+
connection: HubConnection;
|
|
102
|
+
health: HubConnectionHealthInfo;
|
|
103
|
+
}
|
|
87
104
|
interface HubToolSource {
|
|
88
105
|
sourceId: string;
|
|
89
106
|
providerId: string;
|
|
@@ -182,6 +199,31 @@ interface HubPolicyResponse {
|
|
|
182
199
|
interface HubPolicyListResponse {
|
|
183
200
|
policies: HubPolicy[];
|
|
184
201
|
}
|
|
202
|
+
type HubApprovalStatus = "pending" | "approved" | "denied" | "expired" | "consumed";
|
|
203
|
+
interface HubApproval {
|
|
204
|
+
id: string;
|
|
205
|
+
connectionId: string;
|
|
206
|
+
providerId: string;
|
|
207
|
+
actionPath: string;
|
|
208
|
+
inputHash: string;
|
|
209
|
+
requesterPrincipal: Record<string, unknown>;
|
|
210
|
+
status: HubApprovalStatus;
|
|
211
|
+
requestedAt: string;
|
|
212
|
+
expiresAt: string;
|
|
213
|
+
resolvedAt: string | null;
|
|
214
|
+
}
|
|
215
|
+
interface HubApprovalCapabilityToken {
|
|
216
|
+
tokenId: string;
|
|
217
|
+
token: string;
|
|
218
|
+
expiresAt: string;
|
|
219
|
+
}
|
|
220
|
+
interface HubApprovalDecisionResponse {
|
|
221
|
+
approval: HubApproval;
|
|
222
|
+
capabilityToken?: HubApprovalCapabilityToken;
|
|
223
|
+
}
|
|
224
|
+
interface HubApprovalListResponse {
|
|
225
|
+
approvals: HubApproval[];
|
|
226
|
+
}
|
|
185
227
|
interface HubAuditEvent {
|
|
186
228
|
id: string;
|
|
187
229
|
action: string;
|
|
@@ -190,6 +232,15 @@ interface HubAuditEvent {
|
|
|
190
232
|
metadata: unknown;
|
|
191
233
|
createdAt: string;
|
|
192
234
|
}
|
|
235
|
+
interface HubAuditListRequest {
|
|
236
|
+
provider?: string;
|
|
237
|
+
action?: string;
|
|
238
|
+
status?: string;
|
|
239
|
+
since?: string;
|
|
240
|
+
until?: string;
|
|
241
|
+
cursor?: string;
|
|
242
|
+
limit?: number;
|
|
243
|
+
}
|
|
193
244
|
interface HubAuditResponse {
|
|
194
245
|
events: HubAuditEvent[];
|
|
195
246
|
nextCursor: string | null;
|
|
@@ -199,6 +250,54 @@ interface HubUnimplementedErrorEnvelope extends HubErrorEnvelope {
|
|
|
199
250
|
code: "HUB_NOT_IMPLEMENTED";
|
|
200
251
|
};
|
|
201
252
|
}
|
|
253
|
+
interface HubGithubAppMintInstallationTokenRequest {
|
|
254
|
+
/** HTTPS or SSH GitHub URL — alternative to installationId. */
|
|
255
|
+
repoUrl?: string;
|
|
256
|
+
/** Explicit installation id — alternative to repoUrl. */
|
|
257
|
+
installationId?: number;
|
|
258
|
+
/**
|
|
259
|
+
* Permission narrowing. The hub MAY refuse a permission broader than the
|
|
260
|
+
* grant authorized; absent, defaults to `{ contents: "read" }` (the
|
|
261
|
+
* conservative clone-only floor the autonomous-improvement loop needs).
|
|
262
|
+
*/
|
|
263
|
+
permissions?: Record<string, "read" | "write" | "admin">;
|
|
264
|
+
/** Hint passed to GitHub. Server caps at the configured maximum. */
|
|
265
|
+
ttlSeconds?: number;
|
|
266
|
+
}
|
|
267
|
+
interface HubGithubAppMintInstallationTokenResponse {
|
|
268
|
+
token: string;
|
|
269
|
+
expiresAt: string;
|
|
270
|
+
installationId: number;
|
|
271
|
+
owner: string;
|
|
272
|
+
repo: string;
|
|
273
|
+
}
|
|
274
|
+
interface HubGithubAppInstallation {
|
|
275
|
+
installationId: number;
|
|
276
|
+
/** Org/user login the App is installed on (lowercased). */
|
|
277
|
+
accountLogin: string;
|
|
278
|
+
accountType: string | null;
|
|
279
|
+
/** "all" ⇒ every repo under the account; "selected" ⇒ only repoFullNames. */
|
|
280
|
+
repositorySelection: "all" | "selected";
|
|
281
|
+
/** Lowercased "owner/repo" — empty when repositorySelection = "all". */
|
|
282
|
+
repoFullNames: string[];
|
|
283
|
+
suspended: boolean;
|
|
284
|
+
}
|
|
285
|
+
interface HubGithubAppInstallationResponse {
|
|
286
|
+
installation: HubGithubAppInstallation;
|
|
287
|
+
}
|
|
288
|
+
interface HubGithubAppListReposResponse {
|
|
289
|
+
installationId: number;
|
|
290
|
+
/** Lowercased "owner/repo" — covers the full registry view of the install. */
|
|
291
|
+
repoFullNames: string[];
|
|
292
|
+
}
|
|
293
|
+
interface HubGithubAppIsRepoInstalledRequest {
|
|
294
|
+
owner: string;
|
|
295
|
+
repo: string;
|
|
296
|
+
}
|
|
297
|
+
interface HubGithubAppIsRepoInstalledResponse {
|
|
298
|
+
installed: boolean;
|
|
299
|
+
installationId: number | null;
|
|
300
|
+
}
|
|
202
301
|
//#endregion
|
|
203
302
|
//#region src/client.d.ts
|
|
204
303
|
type HubAuthHeaders = () => HeadersInit | Promise<HeadersInit>;
|
|
@@ -216,6 +315,18 @@ declare class HubSdkError extends Error {
|
|
|
216
315
|
status?: number;
|
|
217
316
|
});
|
|
218
317
|
}
|
|
318
|
+
declare const HUB_URL_ENV_VAR: "TANGLE_HUB_URL";
|
|
319
|
+
declare const HUB_API_KEY_ENV_VAR: "TANGLE_API_KEY";
|
|
320
|
+
declare const HUB_CAPABILITY_TOKEN_ENV_VAR: "TANGLE_HUB_CAPABILITY_TOKEN";
|
|
321
|
+
type HubEnv = Record<string, string | undefined>;
|
|
322
|
+
interface HubClientFromEnvOptions {
|
|
323
|
+
env?: HubEnv;
|
|
324
|
+
apiKey?: string;
|
|
325
|
+
authHeaders?: HubAuthHeaders;
|
|
326
|
+
fetch?: typeof fetch;
|
|
327
|
+
}
|
|
328
|
+
declare function resolveHubBaseUrl(env?: HubEnv): string;
|
|
329
|
+
declare function resolveHubAuth(env?: HubEnv): string;
|
|
219
330
|
declare class HubClient {
|
|
220
331
|
readonly baseUrl: string;
|
|
221
332
|
readonly fetch: typeof fetch;
|
|
@@ -225,7 +336,11 @@ declare class HubClient {
|
|
|
225
336
|
readonly permissions: HubPermissionsClient;
|
|
226
337
|
readonly tokens: HubTokensClient;
|
|
227
338
|
readonly tools: HubToolsClient;
|
|
339
|
+
readonly approvals: HubApprovalsClient;
|
|
340
|
+
readonly audit: HubAuditClient;
|
|
341
|
+
readonly githubApp: HubGithubAppClient;
|
|
228
342
|
constructor(options: HubClientOptions);
|
|
343
|
+
static fromEnv(options?: HubClientFromEnvOptions): HubClient;
|
|
229
344
|
status(): Promise<HubStatusResponse>;
|
|
230
345
|
private request;
|
|
231
346
|
private buildHeaders;
|
|
@@ -256,24 +371,55 @@ interface HubToolSearchOptions {
|
|
|
256
371
|
}
|
|
257
372
|
interface HubToolInvokeOptions {
|
|
258
373
|
connectionId?: string;
|
|
374
|
+
approve?: boolean;
|
|
259
375
|
}
|
|
260
376
|
declare class HubToolsClient {
|
|
261
377
|
private readonly request;
|
|
262
378
|
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
263
379
|
search(query: string, options?: HubToolSearchOptions): Promise<HubToolsSearchResponse>;
|
|
380
|
+
sources(): Promise<HubToolSourcesResponse>;
|
|
264
381
|
describe(path: string): Promise<HubToolsDescribeResponse>;
|
|
265
382
|
invoke<TResult = unknown>(path: string, input: unknown, options?: HubToolInvokeOptions): Promise<HubExecResponse<TResult>>;
|
|
266
383
|
private buildExecInit;
|
|
267
384
|
}
|
|
385
|
+
interface HubConnectionStartOptions {
|
|
386
|
+
returnUrl?: string;
|
|
387
|
+
cli?: boolean;
|
|
388
|
+
}
|
|
268
389
|
declare class HubConnectionsClient {
|
|
269
390
|
private readonly request;
|
|
270
391
|
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
271
392
|
list(): Promise<HubConnectionsResponse>;
|
|
393
|
+
start(provider: string, options?: HubConnectionStartOptions): Promise<HubOAuthStartResponse>;
|
|
272
394
|
revoke(connectionId: string): Promise<HubConnectionDeleteResponse>;
|
|
395
|
+
health(connectionId: string): Promise<HubConnectionHealthResponse>;
|
|
396
|
+
}
|
|
397
|
+
declare class HubApprovalsClient {
|
|
398
|
+
private readonly request;
|
|
399
|
+
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
400
|
+
list(): Promise<HubApprovalListResponse>;
|
|
401
|
+
approve(approvalId: string): Promise<HubApprovalDecisionResponse>;
|
|
402
|
+
deny(approvalId: string): Promise<HubApprovalDecisionResponse>;
|
|
403
|
+
}
|
|
404
|
+
declare class HubGithubAppClient {
|
|
405
|
+
private readonly request;
|
|
406
|
+
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
407
|
+
mintInstallationToken(input: HubGithubAppMintInstallationTokenRequest): Promise<HubGithubAppMintInstallationTokenResponse>;
|
|
408
|
+
getInstallation(installationId: number): Promise<HubGithubAppInstallationResponse>;
|
|
409
|
+
listRepos(installationId: number): Promise<HubGithubAppListReposResponse>;
|
|
410
|
+
isRepoInstalled(input: {
|
|
411
|
+
owner: string;
|
|
412
|
+
repo: string;
|
|
413
|
+
}): Promise<HubGithubAppIsRepoInstalledResponse>;
|
|
414
|
+
}
|
|
415
|
+
declare class HubAuditClient {
|
|
416
|
+
private readonly request;
|
|
417
|
+
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
418
|
+
list(options?: HubAuditListRequest): Promise<HubAuditResponse>;
|
|
273
419
|
}
|
|
274
420
|
//#endregion
|
|
275
421
|
//#region src/redaction.d.ts
|
|
276
422
|
declare function redactHubValue(value: unknown): unknown;
|
|
277
423
|
//#endregion
|
|
278
|
-
export { type HubAuditResponse, type HubAuthHeaders, type HubCapabilityToken, HubClient, type HubClientOptions, type HubConnection, type HubConnectionDeleteRequest, type HubConnectionDeleteResponse, HubConnectionsClient, type HubConnectionsResponse, type HubEnvelope, type HubErrorBody, type HubErrorCode, type HubErrorEnvelope, type HubExecRequest, type HubExecResponse, type HubOAuthCallbackErrorQuery, type HubOAuthCallbackQuery, type HubOAuthCallbackResponse, type HubOAuthCallbackSuccessQuery, type HubOAuthStartRequest, type HubOAuthStartResponse, HubPermissionsClient, type HubPolicy, type HubPolicyDecision, type HubPolicyListRequest, type HubPolicyListResponse, type HubPolicyResponse, type HubPolicyUpdateRequest, type HubPrincipal, type HubPrincipalKind, HubSdkError, type HubStatusConnections, type HubStatusResponse, type HubSuccessEnvelope, type HubTokenListOptions, type HubTokenMintRequest, type HubTokenMintResponse, type HubTokenRevokeResponse, HubTokensClient, type HubTokensListResponse, type HubTool, type HubToolInvokeOptions, type HubToolSearchOptions, type HubToolSource, type HubToolSourcesResponse, HubToolsClient, type HubToolsDescribeRequest, type HubToolsDescribeResponse, type HubToolsSearchRequest, type HubToolsSearchResponse, type HubUnimplementedErrorEnvelope, redactHubValue };
|
|
424
|
+
export { HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR, HUB_URL_ENV_VAR, type HubApproval, type HubApprovalCapabilityToken, type HubApprovalDecisionResponse, type HubApprovalStatus, HubApprovalsClient, HubAuditClient, type HubAuditEvent, type HubAuditListRequest, type HubAuditResponse, type HubAuthHeaders, type HubCapabilityToken, HubClient, type HubClientFromEnvOptions, type HubClientOptions, type HubConnection, type HubConnectionDeleteRequest, type HubConnectionDeleteResponse, type HubConnectionHealthError, type HubConnectionHealthInfo, type HubConnectionHealthRequest, type HubConnectionHealthResponse, type HubConnectionHealthStatus, type HubConnectionStartOptions, HubConnectionsClient, type HubConnectionsResponse, type HubEnv, type HubEnvelope, type HubErrorBody, type HubErrorCode, type HubErrorEnvelope, type HubExecRequest, type HubExecResponse, HubGithubAppClient, type HubGithubAppInstallation, type HubGithubAppInstallationResponse, type HubGithubAppIsRepoInstalledRequest, type HubGithubAppIsRepoInstalledResponse, type HubGithubAppListReposResponse, type HubGithubAppMintInstallationTokenRequest, type HubGithubAppMintInstallationTokenResponse, type HubOAuthCallbackErrorQuery, type HubOAuthCallbackQuery, type HubOAuthCallbackResponse, type HubOAuthCallbackSuccessQuery, type HubOAuthStartRequest, type HubOAuthStartResponse, HubPermissionsClient, type HubPolicy, type HubPolicyDecision, type HubPolicyListRequest, type HubPolicyListResponse, type HubPolicyResponse, type HubPolicyUpdateRequest, type HubPrincipal, type HubPrincipalKind, HubSdkError, type HubStatusConnections, type HubStatusResponse, type HubSuccessEnvelope, type HubTokenListOptions, type HubTokenMintRequest, type HubTokenMintResponse, type HubTokenRevokeResponse, HubTokensClient, type HubTokensListResponse, type HubTool, type HubToolInvokeOptions, type HubToolSearchOptions, type HubToolSource, type HubToolSourcesResponse, HubToolsClient, type HubToolsDescribeRequest, type HubToolsDescribeResponse, type HubToolsSearchRequest, type HubToolsSearchResponse, type HubUnimplementedErrorEnvelope, redactHubValue, resolveHubAuth, resolveHubBaseUrl };
|
|
279
425
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/client.ts","../src/redaction.ts"],"mappings":";KAAY,gBAAA;AAAA,UAEK,kBAAA;EACf,OAAA;EACA,IAAA,EAAM,KAAA;AAAA;AAAA,UAGS,gBAAA;EACf,OAAA;EACA,KAAA,EAAO,YAAA;AAAA;AAAA,KAGG,WAAA,UAAqB,kBAAA,CAAmB,KAAA,IAAS,gBAAA;AAAA,UAE5C,YAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA;EACA,OAAA;AAAA;AAAA,KAGU,YAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/client.ts","../src/redaction.ts"],"mappings":";KAAY,gBAAA;AAAA,UAEK,kBAAA;EACf,OAAA;EACA,IAAA,EAAM,KAAA;AAAA;AAAA,UAGS,gBAAA;EACf,OAAA;EACA,KAAA,EAAO,YAAA;AAAA;AAAA,KAGG,WAAA,UAAqB,kBAAA,CAAmB,KAAA,IAAS,gBAAA;AAAA,UAE5C,YAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA;EACA,OAAA;AAAA;AAAA,KAGU,YAAA;AAAA,UAoBK,iBAAA;EACf,QAAA;EACA,SAAA,EAAW,YAAA;EACX,WAAA,EAAa,oBAAA;AAAA;AAAA,UAGE,YAAA;EACf,IAAA,EAAM,gBAAA;EACN,MAAA;EACA,QAAA;EACA,SAAA;EACA,SAAA;AAAA;AAAA,UAGe,oBAAA;EACf,sBAAA;EACA,sBAAA;AAAA;AAAA,UAGe,aAAA;EACf,EAAA;EACA,UAAA;EACA,WAAA;EACA,cAAA;EACA,MAAA;EACA,MAAA;EACA,MAAA;EACA,SAAA;EACA,SAAA;EACA,UAAA;AAAA;AAAA,UAGe,sBAAA;EACf,WAAA,EAAa,aAAA;AAAA;AAAA,UAGE,oBAAA;EACf,QAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,UAGe,4BAAA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AAQ,yCAAA;EAWL,eAAA,CACJ,cAAA,WACC,OAAA,CAAQ,gCAAA;EAOL,SAAA,CACJ,cAAA,WACC,OAAA,CAAQ,6BAAA;EAOL,eAAA,CAAgB,KAAA;IACpB,KAAA;IACA,IAAA;EAAA,IACE,OAAA,CAAQ,mCAAA;AAAA;AAAA,cAYD,cAAA;EAAA,iBAEQ,OAAA;cAAA,OAAA,UACf,IAAA,UACA,IAAA,EAAM,WAAA,KACH,OAAA,CAAQ,KAAA;EAGT,IAAA,CAAK,OAAA,GAAS,mBAAA,GAA2B,OAAA,CAAQ,gBAAA;AAAA;;;iBC/mBzC,cAAA,CAAe,KAAA"}
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,51 @@ var HubSdkError = class extends Error {
|
|
|
21
21
|
this.status = options.status;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
const HUB_URL_ENV_VAR = "TANGLE_HUB_URL";
|
|
25
|
+
const HUB_API_KEY_ENV_VAR = "TANGLE_API_KEY";
|
|
26
|
+
const HUB_CAPABILITY_TOKEN_ENV_VAR = "TANGLE_HUB_CAPABILITY_TOKEN";
|
|
27
|
+
function resolveHubBaseUrl(env = readProcessEnv()) {
|
|
28
|
+
const raw = env[HUB_URL_ENV_VAR];
|
|
29
|
+
if (raw === void 0 || raw.trim() === "") throw new HubSdkError({
|
|
30
|
+
code: "HUB_CONFIG_MISSING",
|
|
31
|
+
message: `${HUB_URL_ENV_VAR} is required`,
|
|
32
|
+
details: { envVar: HUB_URL_ENV_VAR }
|
|
33
|
+
});
|
|
34
|
+
const trimmed = raw.trim();
|
|
35
|
+
try {
|
|
36
|
+
new URL(trimmed);
|
|
37
|
+
} catch {
|
|
38
|
+
throw new HubSdkError({
|
|
39
|
+
code: "HUB_CONFIG_INVALID",
|
|
40
|
+
message: `${HUB_URL_ENV_VAR} is not a valid URL`,
|
|
41
|
+
details: { envVar: HUB_URL_ENV_VAR }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return trimmed.replace(/\/+$/, "").replace(/\/v1\/hub$/, "");
|
|
45
|
+
}
|
|
46
|
+
function resolveHubAuth(env = readProcessEnv()) {
|
|
47
|
+
const present = [nonEmpty(env[HUB_API_KEY_ENV_VAR]), nonEmpty(env[HUB_CAPABILITY_TOKEN_ENV_VAR])].filter((value) => value !== void 0);
|
|
48
|
+
if (present.length === 0) throw new HubSdkError({
|
|
49
|
+
code: "HUB_CONFIG_MISSING",
|
|
50
|
+
message: `One of ${HUB_API_KEY_ENV_VAR} or ${HUB_CAPABILITY_TOKEN_ENV_VAR} is required`,
|
|
51
|
+
details: { envVars: [HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR] }
|
|
52
|
+
});
|
|
53
|
+
if (present.length > 1) throw new HubSdkError({
|
|
54
|
+
code: "HUB_CONFIG_INVALID",
|
|
55
|
+
message: `Set exactly one of ${HUB_API_KEY_ENV_VAR} or ${HUB_CAPABILITY_TOKEN_ENV_VAR}, not both`,
|
|
56
|
+
details: { envVars: [HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR] }
|
|
57
|
+
});
|
|
58
|
+
return present[0];
|
|
59
|
+
}
|
|
60
|
+
function nonEmpty(value) {
|
|
61
|
+
if (value === void 0) return void 0;
|
|
62
|
+
const trimmed = value.trim();
|
|
63
|
+
return trimmed.length === 0 ? void 0 : trimmed;
|
|
64
|
+
}
|
|
65
|
+
function readProcessEnv() {
|
|
66
|
+
return globalThis.process?.env ?? {};
|
|
67
|
+
}
|
|
68
|
+
var HubClient = class HubClient {
|
|
25
69
|
baseUrl;
|
|
26
70
|
fetch;
|
|
27
71
|
apiKey;
|
|
@@ -30,6 +74,9 @@ var HubClient = class {
|
|
|
30
74
|
permissions;
|
|
31
75
|
tokens;
|
|
32
76
|
tools;
|
|
77
|
+
approvals;
|
|
78
|
+
audit;
|
|
79
|
+
githubApp;
|
|
33
80
|
constructor(options) {
|
|
34
81
|
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
35
82
|
this.apiKey = options.apiKey;
|
|
@@ -39,6 +86,18 @@ var HubClient = class {
|
|
|
39
86
|
this.permissions = new HubPermissionsClient((path, init) => this.request(path, init));
|
|
40
87
|
this.tokens = new HubTokensClient((path, init) => this.request(path, init));
|
|
41
88
|
this.tools = new HubToolsClient((path, init) => this.request(path, init));
|
|
89
|
+
this.approvals = new HubApprovalsClient((path, init) => this.request(path, init));
|
|
90
|
+
this.audit = new HubAuditClient((path, init) => this.request(path, init));
|
|
91
|
+
this.githubApp = new HubGithubAppClient((path, init) => this.request(path, init));
|
|
92
|
+
}
|
|
93
|
+
static fromEnv(options = {}) {
|
|
94
|
+
const env = options.env ?? readProcessEnv();
|
|
95
|
+
return new HubClient({
|
|
96
|
+
baseUrl: resolveHubBaseUrl(env),
|
|
97
|
+
apiKey: options.apiKey ?? (options.authHeaders ? void 0 : resolveHubAuth(env)),
|
|
98
|
+
authHeaders: options.authHeaders,
|
|
99
|
+
fetch: options.fetch
|
|
100
|
+
});
|
|
42
101
|
}
|
|
43
102
|
async status() {
|
|
44
103
|
return this.request("/v1/hub/status", { method: "GET" });
|
|
@@ -125,6 +184,9 @@ var HubToolsClient = class {
|
|
|
125
184
|
headers: { "Content-Type": "application/json" }
|
|
126
185
|
});
|
|
127
186
|
}
|
|
187
|
+
async sources() {
|
|
188
|
+
return this.request("/v1/hub/tools/sources", { method: "GET" });
|
|
189
|
+
}
|
|
128
190
|
async describe(path) {
|
|
129
191
|
return this.request("/v1/hub/tools/describe", {
|
|
130
192
|
method: "POST",
|
|
@@ -138,6 +200,24 @@ var HubToolsClient = class {
|
|
|
138
200
|
return await this.request("/v1/hub/exec", execInit);
|
|
139
201
|
} catch (error) {
|
|
140
202
|
if (!(error instanceof HubSdkError) || !requiresCapabilityToken(error)) throw error;
|
|
203
|
+
if (options.approve) {
|
|
204
|
+
const approvalId = getApprovalId(error);
|
|
205
|
+
if (!approvalId) throw error;
|
|
206
|
+
const approved = await this.request(`/v1/hub/approvals/${encodeURIComponent(approvalId)}/approve`, { method: "POST" });
|
|
207
|
+
validateApprovedExecution(approved, path, options.connectionId);
|
|
208
|
+
if (!approved.capabilityToken?.token) throw new HubSdkError({
|
|
209
|
+
code: "HUB_CONFIG_MISSING",
|
|
210
|
+
message: "Hub approval did not return a capability token",
|
|
211
|
+
details: { approvalId }
|
|
212
|
+
});
|
|
213
|
+
return this.request("/v1/hub/exec", {
|
|
214
|
+
...execInit,
|
|
215
|
+
headers: {
|
|
216
|
+
"Content-Type": "application/json",
|
|
217
|
+
Authorization: `Bearer ${approved.capabilityToken.token}`
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
141
221
|
}
|
|
142
222
|
const minted = await this.request("/v1/hub/tokens", {
|
|
143
223
|
method: "POST",
|
|
@@ -171,6 +251,30 @@ var HubToolsClient = class {
|
|
|
171
251
|
function requiresCapabilityToken(error) {
|
|
172
252
|
return error.code === "HUB_APPROVAL_REQUIRED";
|
|
173
253
|
}
|
|
254
|
+
function getApprovalId(error) {
|
|
255
|
+
const id = error.details?.approval?.id;
|
|
256
|
+
return typeof id === "string" ? id : void 0;
|
|
257
|
+
}
|
|
258
|
+
function validateApprovedExecution(approved, path, connectionId) {
|
|
259
|
+
if (approved.approval.actionPath !== path) throw new HubSdkError({
|
|
260
|
+
code: "HUB_POLICY_DENIED",
|
|
261
|
+
message: "Hub approval action does not match requested execution",
|
|
262
|
+
details: {
|
|
263
|
+
approvalId: approved.approval.id,
|
|
264
|
+
expectedActionPath: path,
|
|
265
|
+
approvalActionPath: approved.approval.actionPath
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
if (connectionId !== void 0 && approved.approval.connectionId !== connectionId) throw new HubSdkError({
|
|
269
|
+
code: "HUB_POLICY_DENIED",
|
|
270
|
+
message: "Hub approval connection does not match requested execution",
|
|
271
|
+
details: {
|
|
272
|
+
approvalId: approved.approval.id,
|
|
273
|
+
expectedConnectionId: connectionId,
|
|
274
|
+
approvalConnectionId: approved.approval.connectionId
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
174
278
|
var HubConnectionsClient = class {
|
|
175
279
|
constructor(request) {
|
|
176
280
|
this.request = request;
|
|
@@ -178,11 +282,80 @@ var HubConnectionsClient = class {
|
|
|
178
282
|
async list() {
|
|
179
283
|
return this.request("/v1/hub/connections", { method: "GET" });
|
|
180
284
|
}
|
|
285
|
+
async start(provider, options = {}) {
|
|
286
|
+
return this.request(`/v1/hub/connections/${encodeURIComponent(provider)}/start`, {
|
|
287
|
+
method: "POST",
|
|
288
|
+
body: JSON.stringify({
|
|
289
|
+
returnUrl: options.returnUrl,
|
|
290
|
+
cli: options.cli
|
|
291
|
+
}),
|
|
292
|
+
headers: { "Content-Type": "application/json" }
|
|
293
|
+
});
|
|
294
|
+
}
|
|
181
295
|
async revoke(connectionId) {
|
|
182
296
|
return this.request(`/v1/hub/connections/${encodeURIComponent(connectionId)}`, { method: "DELETE" });
|
|
183
297
|
}
|
|
298
|
+
async health(connectionId) {
|
|
299
|
+
return this.request(`/v1/hub/connections/${encodeURIComponent(connectionId)}/health`, { method: "POST" });
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var HubApprovalsClient = class {
|
|
303
|
+
constructor(request) {
|
|
304
|
+
this.request = request;
|
|
305
|
+
}
|
|
306
|
+
async list() {
|
|
307
|
+
return this.request("/v1/hub/approvals", { method: "GET" });
|
|
308
|
+
}
|
|
309
|
+
async approve(approvalId) {
|
|
310
|
+
return this.request(`/v1/hub/approvals/${encodeURIComponent(approvalId)}/approve`, { method: "POST" });
|
|
311
|
+
}
|
|
312
|
+
async deny(approvalId) {
|
|
313
|
+
return this.request(`/v1/hub/approvals/${encodeURIComponent(approvalId)}/deny`, { method: "POST" });
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var HubGithubAppClient = class {
|
|
317
|
+
constructor(request) {
|
|
318
|
+
this.request = request;
|
|
319
|
+
}
|
|
320
|
+
async mintInstallationToken(input) {
|
|
321
|
+
return this.request("/v1/hub/github-app/mint-installation-token", {
|
|
322
|
+
method: "POST",
|
|
323
|
+
body: JSON.stringify(input),
|
|
324
|
+
headers: { "Content-Type": "application/json" }
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
async getInstallation(installationId) {
|
|
328
|
+
return this.request(`/v1/hub/github-app/installations/${encodeURIComponent(String(installationId))}`, { method: "GET" });
|
|
329
|
+
}
|
|
330
|
+
async listRepos(installationId) {
|
|
331
|
+
return this.request(`/v1/hub/github-app/installations/${encodeURIComponent(String(installationId))}/repos`, { method: "GET" });
|
|
332
|
+
}
|
|
333
|
+
async isRepoInstalled(input) {
|
|
334
|
+
const params = new URLSearchParams({
|
|
335
|
+
owner: input.owner,
|
|
336
|
+
repo: input.repo
|
|
337
|
+
});
|
|
338
|
+
return this.request(`/v1/hub/github-app/is-repo-installed?${params.toString()}`, { method: "GET" });
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
var HubAuditClient = class {
|
|
342
|
+
constructor(request) {
|
|
343
|
+
this.request = request;
|
|
344
|
+
}
|
|
345
|
+
async list(options = {}) {
|
|
346
|
+
const searchParams = new URLSearchParams();
|
|
347
|
+
if (options.provider !== void 0) searchParams.set("provider", options.provider);
|
|
348
|
+
if (options.action !== void 0) searchParams.set("action", options.action);
|
|
349
|
+
if (options.status !== void 0) searchParams.set("status", options.status);
|
|
350
|
+
if (options.since !== void 0) searchParams.set("since", options.since);
|
|
351
|
+
if (options.until !== void 0) searchParams.set("until", options.until);
|
|
352
|
+
if (options.cursor !== void 0) searchParams.set("cursor", options.cursor);
|
|
353
|
+
if (options.limit !== void 0) searchParams.set("limit", String(options.limit));
|
|
354
|
+
const query = searchParams.toString();
|
|
355
|
+
return this.request(`/v1/hub/audit${query ? `?${query}` : ""}`, { method: "GET" });
|
|
356
|
+
}
|
|
184
357
|
};
|
|
185
358
|
//#endregion
|
|
186
|
-
export { HubClient, HubConnectionsClient, HubPermissionsClient, HubSdkError, HubTokensClient, HubToolsClient, redactHubValue };
|
|
359
|
+
export { HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR, HUB_URL_ENV_VAR, HubApprovalsClient, HubAuditClient, HubClient, HubConnectionsClient, HubGithubAppClient, HubPermissionsClient, HubSdkError, HubTokensClient, HubToolsClient, redactHubValue, resolveHubAuth, resolveHubBaseUrl };
|
|
187
360
|
|
|
188
361
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/redaction.ts","../src/client.ts"],"sourcesContent":["const SECRET_KEY_PATTERN =\n /(api[_-]?key|authorization|capability[_-]?token|token|secret)/i;\nconst SECRET_VALUE_PATTERN =\n /\\b(?:sk-tan[-_]|hubcap_|hct_|gh[pousr]_)[A-Za-z0-9_=-]+\\b/g;\n\nexport function redactHubValue(value: unknown): unknown {\n if (typeof value === \"string\") {\n return value.replace(SECRET_VALUE_PATTERN, \"[REDACTED]\");\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => redactHubValue(item));\n }\n\n if (value && typeof value === \"object\") {\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [\n key,\n SECRET_KEY_PATTERN.test(key)\n ? \"[REDACTED]\"\n : redactHubValue(entryValue),\n ]),\n );\n }\n\n return value;\n}\n","import { redactHubValue } from \"./redaction.js\";\nimport type {\n HubConnectionDeleteResponse,\n HubConnectionsResponse,\n HubEnvelope,\n HubErrorBody,\n HubExecResponse,\n HubPolicyListResponse,\n HubPolicyResponse,\n HubPolicyUpdateRequest,\n HubStatusResponse,\n HubTokenMintResponse,\n HubTokenRevokeResponse,\n HubTokensListResponse,\n HubToolsDescribeResponse,\n HubToolsSearchResponse,\n} from \"./types.js\";\n\nexport type HubAuthHeaders = () => HeadersInit | Promise<HeadersInit>;\n\nexport interface HubClientOptions {\n baseUrl: string;\n apiKey?: string;\n authHeaders?: HubAuthHeaders;\n fetch?: typeof fetch;\n}\n\nexport class HubSdkError extends Error {\n readonly code: HubErrorBody[\"code\"];\n readonly details?: unknown;\n readonly status?: number;\n\n constructor(error: HubErrorBody, options: { status?: number } = {}) {\n super(String(redactHubValue(error.message)));\n this.name = \"HubSdkError\";\n this.code = error.code;\n this.details = redactHubValue(error.details);\n this.status = options.status;\n }\n}\n\nexport class HubClient {\n readonly baseUrl: string;\n readonly fetch: typeof fetch;\n readonly apiKey?: string;\n readonly authHeaders?: HubAuthHeaders;\n readonly connections: HubConnectionsClient;\n readonly permissions: HubPermissionsClient;\n readonly tokens: HubTokensClient;\n readonly tools: HubToolsClient;\n\n constructor(options: HubClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/+$/, \"\");\n this.apiKey = options.apiKey;\n this.authHeaders = options.authHeaders;\n this.fetch = options.fetch ?? fetch;\n this.connections = new HubConnectionsClient((path, init) =>\n this.request(path, init),\n );\n this.permissions = new HubPermissionsClient((path, init) =>\n this.request(path, init),\n );\n this.tokens = new HubTokensClient((path, init) => this.request(path, init));\n this.tools = new HubToolsClient((path, init) => this.request(path, init));\n }\n\n async status(): Promise<HubStatusResponse> {\n return this.request<HubStatusResponse>(\"/v1/hub/status\", { method: \"GET\" });\n }\n\n private async request<TData>(\n path: string,\n init: RequestInit,\n ): Promise<TData> {\n const response = await this.fetch(`${this.baseUrl}${path}`, {\n ...init,\n headers: await this.buildHeaders(init.headers),\n });\n const envelope = (await response.json()) as HubEnvelope<TData>;\n\n if (!envelope.success) {\n throw new HubSdkError(envelope.error, { status: response.status });\n }\n\n return envelope.data;\n }\n\n private async buildHeaders(headers: HeadersInit | undefined) {\n const mergedHeaders = new Headers(headers);\n mergedHeaders.set(\"Accept\", \"application/json\");\n\n if (this.apiKey) {\n mergedHeaders.set(\"Authorization\", `Bearer ${this.apiKey}`);\n }\n\n if (this.authHeaders) {\n for (const [key, value] of new Headers(await this.authHeaders())) {\n mergedHeaders.set(key, value);\n }\n }\n\n for (const [key, value] of new Headers(headers)) {\n mergedHeaders.set(key, value);\n }\n\n return mergedHeaders;\n }\n}\n\nexport interface HubTokenListOptions {\n includeExpired?: boolean;\n}\n\nexport class HubTokensClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async mint(options: {\n actionPath: string;\n connectionId?: string;\n provider?: string;\n ttlSeconds?: number;\n }): Promise<HubTokenMintResponse> {\n return this.request<HubTokenMintResponse>(\"/v1/hub/tokens\", {\n method: \"POST\",\n body: JSON.stringify(options),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n async list(\n options: HubTokenListOptions = {},\n ): Promise<HubTokensListResponse> {\n const searchParams = new URLSearchParams();\n if (options.includeExpired) searchParams.set(\"includeExpired\", \"true\");\n const query = searchParams.toString();\n const response = await this.request<HubTokensListResponse>(\n `/v1/hub/tokens${query ? `?${query}` : \"\"}`,\n { method: \"GET\" },\n );\n return {\n tokens: response.tokens.map((token) => ({\n id: token.id,\n providerId: token.providerId,\n connectionId: token.connectionId,\n connectionDisplay: token.connectionDisplay,\n actionPath: token.actionPath,\n expiresAt: token.expiresAt,\n status: token.status,\n principalKind: token.principalKind,\n createdAt: token.createdAt,\n })),\n };\n }\n\n async revoke(tokenId: string): Promise<HubTokenRevokeResponse> {\n const response = await this.request<HubTokenRevokeResponse>(\n `/v1/hub/tokens/${encodeURIComponent(tokenId)}`,\n { method: \"DELETE\" },\n );\n return {\n tokenId: response.tokenId,\n status: response.status,\n };\n }\n}\n\nexport class HubPermissionsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async list(connectionId: string): Promise<HubPolicyListResponse> {\n return this.request<HubPolicyListResponse>(\n `/v1/hub/policies?connectionId=${encodeURIComponent(connectionId)}`,\n { method: \"GET\" },\n );\n }\n\n async set(input: HubPolicyUpdateRequest): Promise<HubPolicyResponse> {\n return this.request<HubPolicyResponse>(\"/v1/hub/policies\", {\n method: \"PUT\",\n body: JSON.stringify(input),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n}\n\nexport interface HubToolSearchOptions {\n provider?: string;\n}\n\nexport interface HubToolInvokeOptions {\n connectionId?: string;\n}\n\nexport class HubToolsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async search(\n query: string,\n options: HubToolSearchOptions = {},\n ): Promise<HubToolsSearchResponse> {\n return this.request<HubToolsSearchResponse>(\"/v1/hub/tools/search\", {\n method: \"POST\",\n body: JSON.stringify({ query, provider: options.provider }),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n async describe(path: string): Promise<HubToolsDescribeResponse> {\n return this.request<HubToolsDescribeResponse>(\"/v1/hub/tools/describe\", {\n method: \"POST\",\n body: JSON.stringify({ path }),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n async invoke<TResult = unknown>(\n path: string,\n input: unknown,\n options: HubToolInvokeOptions = {},\n ): Promise<HubExecResponse<TResult>> {\n const execInit = this.buildExecInit(path, input, options.connectionId);\n try {\n return await this.request<HubExecResponse<TResult>>(\n \"/v1/hub/exec\",\n execInit,\n );\n } catch (error) {\n if (!(error instanceof HubSdkError) || !requiresCapabilityToken(error)) {\n throw error;\n }\n }\n\n const minted = await this.request<HubTokenMintResponse>(\"/v1/hub/tokens\", {\n method: \"POST\",\n body: JSON.stringify({\n actionPath: path,\n connectionId: options.connectionId,\n provider: options.connectionId ? undefined : path.split(\".\")[0],\n }),\n headers: { \"Content-Type\": \"application/json\" },\n });\n\n return this.request<HubExecResponse<TResult>>(\"/v1/hub/exec\", {\n ...execInit,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${minted.token}`,\n },\n });\n }\n\n private buildExecInit(\n path: string,\n input: unknown,\n connectionId: string | undefined,\n ): RequestInit {\n return {\n method: \"POST\",\n body: JSON.stringify({ path, input, connectionId }),\n headers: { \"Content-Type\": \"application/json\" },\n };\n }\n}\n\nfunction requiresCapabilityToken(error: HubSdkError): boolean {\n return error.code === \"HUB_APPROVAL_REQUIRED\";\n}\n\nexport class HubConnectionsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async list(): Promise<HubConnectionsResponse> {\n return this.request<HubConnectionsResponse>(\"/v1/hub/connections\", {\n method: \"GET\",\n });\n }\n\n async revoke(connectionId: string): Promise<HubConnectionDeleteResponse> {\n return this.request<HubConnectionDeleteResponse>(\n `/v1/hub/connections/${encodeURIComponent(connectionId)}`,\n { method: \"DELETE\" },\n );\n }\n}\n"],"mappings":";AAAA,MAAM,qBACJ;AACF,MAAM,uBACJ;AAEF,SAAgB,eAAe,OAAyB;AACtD,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,QAAQ,sBAAsB,aAAa;AAG1D,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,KAAK,SAAS,eAAe,KAAK,CAAC;AAGlD,KAAI,SAAS,OAAO,UAAU,SAC5B,QAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,gBAAgB,CAC/C,KACA,mBAAmB,KAAK,IAAI,GACxB,eACA,eAAe,WAAW,CAC/B,CAAC,CACH;AAGH,QAAO;;;;ACET,IAAa,cAAb,cAAiC,MAAM;CACrC;CACA;CACA;CAEA,YAAY,OAAqB,UAA+B,EAAE,EAAE;AAClE,QAAM,OAAO,eAAe,MAAM,QAAQ,CAAC,CAAC;AAC5C,OAAK,OAAO;AACZ,OAAK,OAAO,MAAM;AAClB,OAAK,UAAU,eAAe,MAAM,QAAQ;AAC5C,OAAK,SAAS,QAAQ;;;AAI1B,IAAa,YAAb,MAAuB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA2B;AACrC,OAAK,UAAU,QAAQ,QAAQ,QAAQ,QAAQ,GAAG;AAClD,OAAK,SAAS,QAAQ;AACtB,OAAK,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AACvE,SAAO,KAAK,QACV,uBAAuB,mBAAmB,aAAa,IACvD,EAAE,QAAQ,UAAU,CACrB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/redaction.ts","../src/client.ts"],"sourcesContent":["const SECRET_KEY_PATTERN =\n /(api[_-]?key|authorization|capability[_-]?token|token|secret)/i;\nconst SECRET_VALUE_PATTERN =\n /\\b(?:sk-tan[-_]|hubcap_|hct_|gh[pousr]_)[A-Za-z0-9_=-]+\\b/g;\n\nexport function redactHubValue(value: unknown): unknown {\n if (typeof value === \"string\") {\n return value.replace(SECRET_VALUE_PATTERN, \"[REDACTED]\");\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => redactHubValue(item));\n }\n\n if (value && typeof value === \"object\") {\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [\n key,\n SECRET_KEY_PATTERN.test(key)\n ? \"[REDACTED]\"\n : redactHubValue(entryValue),\n ]),\n );\n }\n\n return value;\n}\n","import { redactHubValue } from \"./redaction.js\";\nimport type {\n HubApprovalDecisionResponse,\n HubApprovalListResponse,\n HubAuditListRequest,\n HubAuditResponse,\n HubConnectionDeleteResponse,\n HubConnectionHealthResponse,\n HubConnectionsResponse,\n HubEnvelope,\n HubErrorBody,\n HubExecResponse,\n HubGithubAppInstallationResponse,\n HubGithubAppIsRepoInstalledResponse,\n HubGithubAppListReposResponse,\n HubGithubAppMintInstallationTokenRequest,\n HubGithubAppMintInstallationTokenResponse,\n HubOAuthStartResponse,\n HubPolicyListResponse,\n HubPolicyResponse,\n HubPolicyUpdateRequest,\n HubStatusResponse,\n HubTokenMintResponse,\n HubTokenRevokeResponse,\n HubTokensListResponse,\n HubToolSourcesResponse,\n HubToolsDescribeResponse,\n HubToolsSearchResponse,\n} from \"./types.js\";\n\nexport type HubAuthHeaders = () => HeadersInit | Promise<HeadersInit>;\n\nexport interface HubClientOptions {\n baseUrl: string;\n apiKey?: string;\n authHeaders?: HubAuthHeaders;\n fetch?: typeof fetch;\n}\n\nexport class HubSdkError extends Error {\n readonly code: HubErrorBody[\"code\"];\n readonly details?: unknown;\n readonly status?: number;\n\n constructor(error: HubErrorBody, options: { status?: number } = {}) {\n super(String(redactHubValue(error.message)));\n this.name = \"HubSdkError\";\n this.code = error.code;\n this.details = redactHubValue(error.details);\n this.status = options.status;\n }\n}\n\n// Wire-contract env var names. Mirrored from\n// products/platform/api/src/lib/hub-sandbox-contract.ts where the same\n// literals are pinned by `z.literal(...)`. Any drift here is a contract break.\nexport const HUB_URL_ENV_VAR = \"TANGLE_HUB_URL\" as const;\nexport const HUB_API_KEY_ENV_VAR = \"TANGLE_API_KEY\" as const;\nexport const HUB_CAPABILITY_TOKEN_ENV_VAR =\n \"TANGLE_HUB_CAPABILITY_TOKEN\" as const;\n\nexport type HubEnv = Record<string, string | undefined>;\n\nexport interface HubClientFromEnvOptions {\n env?: HubEnv;\n apiKey?: string;\n authHeaders?: HubAuthHeaders;\n fetch?: typeof fetch;\n}\n\n// Read TANGLE_HUB_URL from env. Strips trailing slashes and the optional\n// `/v1/hub` suffix so the result is the platform root the SDK appends\n// `/v1/hub/...` to. No default — throws HubSdkError on undefined / empty /\n// non-URL. SaaS vs on-prem flips via env only.\nexport function resolveHubBaseUrl(env: HubEnv = readProcessEnv()): string {\n const raw = env[HUB_URL_ENV_VAR];\n if (raw === undefined || raw.trim() === \"\") {\n throw new HubSdkError({\n code: \"HUB_CONFIG_MISSING\",\n message: `${HUB_URL_ENV_VAR} is required`,\n details: { envVar: HUB_URL_ENV_VAR },\n });\n }\n\n const trimmed = raw.trim();\n try {\n new URL(trimmed);\n } catch {\n throw new HubSdkError({\n code: \"HUB_CONFIG_INVALID\",\n message: `${HUB_URL_ENV_VAR} is not a valid URL`,\n details: { envVar: HUB_URL_ENV_VAR },\n });\n }\n\n return trimmed.replace(/\\/+$/, \"\").replace(/\\/v1\\/hub$/, \"\");\n}\n\n// Read exactly one Hub auth credential. Mirrors the\n// `exactly-one-api-key-or-capability-token` rule on the platform-api\n// hubSandboxEnvironmentSchema superRefine. No default; throws on none-or-both.\nexport function resolveHubAuth(env: HubEnv = readProcessEnv()): string {\n const apiKey = nonEmpty(env[HUB_API_KEY_ENV_VAR]);\n const capabilityToken = nonEmpty(env[HUB_CAPABILITY_TOKEN_ENV_VAR]);\n const present = [apiKey, capabilityToken].filter(\n (value): value is string => value !== undefined,\n );\n\n if (present.length === 0) {\n throw new HubSdkError({\n code: \"HUB_CONFIG_MISSING\",\n message: `One of ${HUB_API_KEY_ENV_VAR} or ${HUB_CAPABILITY_TOKEN_ENV_VAR} is required`,\n details: {\n envVars: [HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR],\n },\n });\n }\n if (present.length > 1) {\n throw new HubSdkError({\n code: \"HUB_CONFIG_INVALID\",\n message: `Set exactly one of ${HUB_API_KEY_ENV_VAR} or ${HUB_CAPABILITY_TOKEN_ENV_VAR}, not both`,\n details: {\n envVars: [HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR],\n },\n });\n }\n\n return present[0];\n}\n\nfunction nonEmpty(value: string | undefined): string | undefined {\n if (value === undefined) return undefined;\n const trimmed = value.trim();\n return trimmed.length === 0 ? undefined : trimmed;\n}\n\nfunction readProcessEnv(): HubEnv {\n // Browsers / Workers may not expose `process`. Callers there must pass `env`.\n const proc = (globalThis as { process?: { env?: HubEnv } }).process;\n return proc?.env ?? {};\n}\n\nexport class HubClient {\n readonly baseUrl: string;\n readonly fetch: typeof fetch;\n readonly apiKey?: string;\n readonly authHeaders?: HubAuthHeaders;\n readonly connections: HubConnectionsClient;\n readonly permissions: HubPermissionsClient;\n readonly tokens: HubTokensClient;\n readonly tools: HubToolsClient;\n readonly approvals: HubApprovalsClient;\n readonly audit: HubAuditClient;\n readonly githubApp: HubGithubAppClient;\n\n constructor(options: HubClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/+$/, \"\");\n this.apiKey = options.apiKey;\n this.authHeaders = options.authHeaders;\n this.fetch = options.fetch ?? fetch;\n this.connections = new HubConnectionsClient((path, init) =>\n this.request(path, init),\n );\n this.permissions = new HubPermissionsClient((path, init) =>\n this.request(path, init),\n );\n this.tokens = new HubTokensClient((path, init) => this.request(path, init));\n this.tools = new HubToolsClient((path, init) => this.request(path, init));\n this.approvals = new HubApprovalsClient((path, init) =>\n this.request(path, init),\n );\n this.audit = new HubAuditClient((path, init) => this.request(path, init));\n this.githubApp = new HubGithubAppClient((path, init) =>\n this.request(path, init),\n );\n }\n\n // Static factory: construct a HubClient from environment variables.\n // Required: TANGLE_HUB_URL. Auth: exactly one of TANGLE_API_KEY or\n // TANGLE_HUB_CAPABILITY_TOKEN (skip the env auth resolve by passing\n // `apiKey` / `authHeaders` explicitly). No fallback — throws HubSdkError\n // with HUB_CONFIG_MISSING / HUB_CONFIG_INVALID when env is incomplete.\n // SaaS vs on-prem flips via env only.\n static fromEnv(options: HubClientFromEnvOptions = {}): HubClient {\n const env = options.env ?? readProcessEnv();\n const baseUrl = resolveHubBaseUrl(env);\n const apiKey =\n options.apiKey ?? (options.authHeaders ? undefined : resolveHubAuth(env));\n return new HubClient({\n baseUrl,\n apiKey,\n authHeaders: options.authHeaders,\n fetch: options.fetch,\n });\n }\n\n async status(): Promise<HubStatusResponse> {\n return this.request<HubStatusResponse>(\"/v1/hub/status\", { method: \"GET\" });\n }\n\n private async request<TData>(\n path: string,\n init: RequestInit,\n ): Promise<TData> {\n const response = await this.fetch(`${this.baseUrl}${path}`, {\n ...init,\n headers: await this.buildHeaders(init.headers),\n });\n const envelope = (await response.json()) as HubEnvelope<TData>;\n\n if (!envelope.success) {\n throw new HubSdkError(envelope.error, { status: response.status });\n }\n\n return envelope.data;\n }\n\n private async buildHeaders(headers: HeadersInit | undefined) {\n const mergedHeaders = new Headers(headers);\n mergedHeaders.set(\"Accept\", \"application/json\");\n\n if (this.apiKey) {\n mergedHeaders.set(\"Authorization\", `Bearer ${this.apiKey}`);\n }\n\n if (this.authHeaders) {\n for (const [key, value] of new Headers(await this.authHeaders())) {\n mergedHeaders.set(key, value);\n }\n }\n\n for (const [key, value] of new Headers(headers)) {\n mergedHeaders.set(key, value);\n }\n\n return mergedHeaders;\n }\n}\n\nexport interface HubTokenListOptions {\n includeExpired?: boolean;\n}\n\nexport class HubTokensClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async mint(options: {\n actionPath: string;\n connectionId?: string;\n provider?: string;\n ttlSeconds?: number;\n }): Promise<HubTokenMintResponse> {\n return this.request<HubTokenMintResponse>(\"/v1/hub/tokens\", {\n method: \"POST\",\n body: JSON.stringify(options),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n async list(\n options: HubTokenListOptions = {},\n ): Promise<HubTokensListResponse> {\n const searchParams = new URLSearchParams();\n if (options.includeExpired) searchParams.set(\"includeExpired\", \"true\");\n const query = searchParams.toString();\n const response = await this.request<HubTokensListResponse>(\n `/v1/hub/tokens${query ? `?${query}` : \"\"}`,\n { method: \"GET\" },\n );\n return {\n tokens: response.tokens.map((token) => ({\n id: token.id,\n providerId: token.providerId,\n connectionId: token.connectionId,\n connectionDisplay: token.connectionDisplay,\n actionPath: token.actionPath,\n expiresAt: token.expiresAt,\n status: token.status,\n principalKind: token.principalKind,\n createdAt: token.createdAt,\n })),\n };\n }\n\n async revoke(tokenId: string): Promise<HubTokenRevokeResponse> {\n const response = await this.request<HubTokenRevokeResponse>(\n `/v1/hub/tokens/${encodeURIComponent(tokenId)}`,\n { method: \"DELETE\" },\n );\n return {\n tokenId: response.tokenId,\n status: response.status,\n };\n }\n}\n\nexport class HubPermissionsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async list(connectionId: string): Promise<HubPolicyListResponse> {\n return this.request<HubPolicyListResponse>(\n `/v1/hub/policies?connectionId=${encodeURIComponent(connectionId)}`,\n { method: \"GET\" },\n );\n }\n\n async set(input: HubPolicyUpdateRequest): Promise<HubPolicyResponse> {\n return this.request<HubPolicyResponse>(\"/v1/hub/policies\", {\n method: \"PUT\",\n body: JSON.stringify(input),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n}\n\nexport interface HubToolSearchOptions {\n provider?: string;\n}\n\nexport interface HubToolInvokeOptions {\n connectionId?: string;\n approve?: boolean;\n}\n\nexport class HubToolsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async search(\n query: string,\n options: HubToolSearchOptions = {},\n ): Promise<HubToolsSearchResponse> {\n return this.request<HubToolsSearchResponse>(\"/v1/hub/tools/search\", {\n method: \"POST\",\n body: JSON.stringify({ query, provider: options.provider }),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n async sources(): Promise<HubToolSourcesResponse> {\n return this.request<HubToolSourcesResponse>(\"/v1/hub/tools/sources\", {\n method: \"GET\",\n });\n }\n\n async describe(path: string): Promise<HubToolsDescribeResponse> {\n return this.request<HubToolsDescribeResponse>(\"/v1/hub/tools/describe\", {\n method: \"POST\",\n body: JSON.stringify({ path }),\n headers: { \"Content-Type\": \"application/json\" },\n });\n }\n\n async invoke<TResult = unknown>(\n path: string,\n input: unknown,\n options: HubToolInvokeOptions = {},\n ): Promise<HubExecResponse<TResult>> {\n const execInit = this.buildExecInit(path, input, options.connectionId);\n try {\n return await this.request<HubExecResponse<TResult>>(\n \"/v1/hub/exec\",\n execInit,\n );\n } catch (error) {\n if (!(error instanceof HubSdkError) || !requiresCapabilityToken(error)) {\n throw error;\n }\n if (options.approve) {\n const approvalId = getApprovalId(error);\n if (!approvalId) throw error;\n const approved = await this.request<HubApprovalDecisionResponse>(\n `/v1/hub/approvals/${encodeURIComponent(approvalId)}/approve`,\n { method: \"POST\" },\n );\n validateApprovedExecution(approved, path, options.connectionId);\n if (!approved.capabilityToken?.token) {\n throw new HubSdkError({\n code: \"HUB_CONFIG_MISSING\",\n message: \"Hub approval did not return a capability token\",\n details: { approvalId },\n });\n }\n return this.request<HubExecResponse<TResult>>(\"/v1/hub/exec\", {\n ...execInit,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${approved.capabilityToken.token}`,\n },\n });\n }\n }\n\n const minted = await this.request<HubTokenMintResponse>(\"/v1/hub/tokens\", {\n method: \"POST\",\n body: JSON.stringify({\n actionPath: path,\n connectionId: options.connectionId,\n provider: options.connectionId ? undefined : path.split(\".\")[0],\n }),\n headers: { \"Content-Type\": \"application/json\" },\n });\n\n return this.request<HubExecResponse<TResult>>(\"/v1/hub/exec\", {\n ...execInit,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${minted.token}`,\n },\n });\n }\n\n private buildExecInit(\n path: string,\n input: unknown,\n connectionId: string | undefined,\n ): RequestInit {\n return {\n method: \"POST\",\n body: JSON.stringify({ path, input, connectionId }),\n headers: { \"Content-Type\": \"application/json\" },\n };\n }\n}\n\nfunction requiresCapabilityToken(error: HubSdkError): boolean {\n return error.code === \"HUB_APPROVAL_REQUIRED\";\n}\n\nfunction getApprovalId(error: HubSdkError): string | undefined {\n const id = (error.details as { approval?: { id?: unknown } } | undefined)\n ?.approval?.id;\n return typeof id === \"string\" ? id : undefined;\n}\n\nfunction validateApprovedExecution(\n approved: HubApprovalDecisionResponse,\n path: string,\n connectionId: string | undefined,\n): void {\n if (approved.approval.actionPath !== path) {\n throw new HubSdkError({\n code: \"HUB_POLICY_DENIED\",\n message: \"Hub approval action does not match requested execution\",\n details: {\n approvalId: approved.approval.id,\n expectedActionPath: path,\n approvalActionPath: approved.approval.actionPath,\n },\n });\n }\n if (\n connectionId !== undefined &&\n approved.approval.connectionId !== connectionId\n ) {\n throw new HubSdkError({\n code: \"HUB_POLICY_DENIED\",\n message: \"Hub approval connection does not match requested execution\",\n details: {\n approvalId: approved.approval.id,\n expectedConnectionId: connectionId,\n approvalConnectionId: approved.approval.connectionId,\n },\n });\n }\n}\n\nexport interface HubConnectionStartOptions {\n returnUrl?: string;\n cli?: boolean;\n}\n\nexport class HubConnectionsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async list(): Promise<HubConnectionsResponse> {\n return this.request<HubConnectionsResponse>(\"/v1/hub/connections\", {\n method: \"GET\",\n });\n }\n\n async start(\n provider: string,\n options: HubConnectionStartOptions = {},\n ): Promise<HubOAuthStartResponse> {\n return this.request<HubOAuthStartResponse>(\n `/v1/hub/connections/${encodeURIComponent(provider)}/start`,\n {\n method: \"POST\",\n body: JSON.stringify({\n returnUrl: options.returnUrl,\n cli: options.cli,\n }),\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n async revoke(connectionId: string): Promise<HubConnectionDeleteResponse> {\n return this.request<HubConnectionDeleteResponse>(\n `/v1/hub/connections/${encodeURIComponent(connectionId)}`,\n { method: \"DELETE\" },\n );\n }\n\n async health(connectionId: string): Promise<HubConnectionHealthResponse> {\n return this.request<HubConnectionHealthResponse>(\n `/v1/hub/connections/${encodeURIComponent(connectionId)}/health`,\n { method: \"POST\" },\n );\n }\n}\n\nexport class HubApprovalsClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async list(): Promise<HubApprovalListResponse> {\n return this.request<HubApprovalListResponse>(\"/v1/hub/approvals\", {\n method: \"GET\",\n });\n }\n\n async approve(approvalId: string): Promise<HubApprovalDecisionResponse> {\n return this.request<HubApprovalDecisionResponse>(\n `/v1/hub/approvals/${encodeURIComponent(approvalId)}/approve`,\n { method: \"POST\" },\n );\n }\n\n async deny(approvalId: string): Promise<HubApprovalDecisionResponse> {\n return this.request<HubApprovalDecisionResponse>(\n `/v1/hub/approvals/${encodeURIComponent(approvalId)}/deny`,\n { method: \"POST\" },\n );\n }\n}\n\n// GitHub App primitive. The hub holds the App PEM + the per-tenant\n// installation grants; consumers (intelligence autonomous-improvement loop,\n// future code reviewers) ask the hub to mint a short-lived repo-scoped\n// installation token. The mint call MUST be principal-authed; the hub refuses\n// without a matching grant for the calling principal.\nexport class HubGithubAppClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async mintInstallationToken(\n input: HubGithubAppMintInstallationTokenRequest,\n ): Promise<HubGithubAppMintInstallationTokenResponse> {\n return this.request<HubGithubAppMintInstallationTokenResponse>(\n \"/v1/hub/github-app/mint-installation-token\",\n {\n method: \"POST\",\n body: JSON.stringify(input),\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n async getInstallation(\n installationId: number,\n ): Promise<HubGithubAppInstallationResponse> {\n return this.request<HubGithubAppInstallationResponse>(\n `/v1/hub/github-app/installations/${encodeURIComponent(String(installationId))}`,\n { method: \"GET\" },\n );\n }\n\n async listRepos(\n installationId: number,\n ): Promise<HubGithubAppListReposResponse> {\n return this.request<HubGithubAppListReposResponse>(\n `/v1/hub/github-app/installations/${encodeURIComponent(String(installationId))}/repos`,\n { method: \"GET\" },\n );\n }\n\n async isRepoInstalled(input: {\n owner: string;\n repo: string;\n }): Promise<HubGithubAppIsRepoInstalledResponse> {\n const params = new URLSearchParams({\n owner: input.owner,\n repo: input.repo,\n });\n return this.request<HubGithubAppIsRepoInstalledResponse>(\n `/v1/hub/github-app/is-repo-installed?${params.toString()}`,\n { method: \"GET\" },\n );\n }\n}\n\nexport class HubAuditClient {\n constructor(\n private readonly request: <TData>(\n path: string,\n init: RequestInit,\n ) => Promise<TData>,\n ) {}\n\n async list(options: HubAuditListRequest = {}): Promise<HubAuditResponse> {\n const searchParams = new URLSearchParams();\n if (options.provider !== undefined)\n searchParams.set(\"provider\", options.provider);\n if (options.action !== undefined)\n searchParams.set(\"action\", options.action);\n if (options.status !== undefined)\n searchParams.set(\"status\", options.status);\n if (options.since !== undefined) searchParams.set(\"since\", options.since);\n if (options.until !== undefined) searchParams.set(\"until\", options.until);\n if (options.cursor !== undefined)\n searchParams.set(\"cursor\", options.cursor);\n if (options.limit !== undefined)\n searchParams.set(\"limit\", String(options.limit));\n const query = searchParams.toString();\n return this.request<HubAuditResponse>(\n `/v1/hub/audit${query ? `?${query}` : \"\"}`,\n { method: \"GET\" },\n );\n }\n}\n"],"mappings":";AAAA,MAAM,qBACJ;AACF,MAAM,uBACJ;AAEF,SAAgB,eAAe,OAAyB;AACtD,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,QAAQ,sBAAsB,aAAa;AAG1D,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,KAAK,SAAS,eAAe,KAAK,CAAC;AAGlD,KAAI,SAAS,OAAO,UAAU,SAC5B,QAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,gBAAgB,CAC/C,KACA,mBAAmB,KAAK,IAAI,GACxB,eACA,eAAe,WAAW,CAC/B,CAAC,CACH;AAGH,QAAO;;;;ACcT,IAAa,cAAb,cAAiC,MAAM;CACrC;CACA;CACA;CAEA,YAAY,OAAqB,UAA+B,EAAE,EAAE;AAClE,QAAM,OAAO,eAAe,MAAM,QAAQ,CAAC,CAAC;AAC5C,OAAK,OAAO;AACZ,OAAK,OAAO,MAAM;AAClB,OAAK,UAAU,eAAe,MAAM,QAAQ;AAC5C,OAAK,SAAS,QAAQ;;;AAO1B,MAAa,kBAAkB;AAC/B,MAAa,sBAAsB;AACnC,MAAa,+BACX;AAeF,SAAgB,kBAAkB,MAAc,gBAAgB,EAAU;CACxE,MAAM,MAAM,IAAI;AAChB,KAAI,QAAQ,KAAA,KAAa,IAAI,MAAM,KAAK,GACtC,OAAM,IAAI,YAAY;EACpB,MAAM;EACN,SAAS,GAAG,gBAAgB;EAC5B,SAAS,EAAE,QAAQ,iBAAiB;EACrC,CAAC;CAGJ,MAAM,UAAU,IAAI,MAAM;AAC1B,KAAI;AACF,MAAI,IAAI,QAAQ;SACV;AACN,QAAM,IAAI,YAAY;GACpB,MAAM;GACN,SAAS,GAAG,gBAAgB;GAC5B,SAAS,EAAE,QAAQ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B,OAAO,eAAe,CAAC,CAAC,SAC/E,EAAE,QAAQ,OAAO,CAClB;;CAGH,MAAM,gBAAgB,OAG2B;EAC/C,MAAM,SAAS,IAAI,gBAAgB;GACjC,OAAO,MAAM;GACb,MAAM,MAAM;GACb,CAAC;AACF,SAAO,KAAK,QACV,wCAAwC,OAAO,UAAU,IACzD,EAAE,QAAQ,OAAO,CAClB;;;AAIL,IAAa,iBAAb,MAA4B;CAC1B,YACE,SAIA;AAJiB,OAAA,UAAA;;CAMnB,MAAM,KAAK,UAA+B,EAAE,EAA6B;EACvE,MAAM,eAAe,IAAI,iBAAiB;AAC1C,MAAI,QAAQ,aAAa,KAAA,EACvB,cAAa,IAAI,YAAY,QAAQ,SAAS;AAChD,MAAI,QAAQ,WAAW,KAAA,EACrB,cAAa,IAAI,UAAU,QAAQ,OAAO;AAC5C,MAAI,QAAQ,WAAW,KAAA,EACrB,cAAa,IAAI,UAAU,QAAQ,OAAO;AAC5C,MAAI,QAAQ,UAAU,KAAA,EAAW,cAAa,IAAI,SAAS,QAAQ,MAAM;AACzE,MAAI,QAAQ,UAAU,KAAA,EAAW,cAAa,IAAI,SAAS,QAAQ,MAAM;AACzE,MAAI,QAAQ,WAAW,KAAA,EACrB,cAAa,IAAI,UAAU,QAAQ,OAAO;AAC5C,MAAI,QAAQ,UAAU,KAAA,EACpB,cAAa,IAAI,SAAS,OAAO,QAAQ,MAAM,CAAC;EAClD,MAAM,QAAQ,aAAa,UAAU;AACrC,SAAO,KAAK,QACV,gBAAgB,QAAQ,IAAI,UAAU,MACtC,EAAE,QAAQ,OAAO,CAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/hub-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Typed SDK for Tangle Hub tool discovery and execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "25.6.0",
|
|
19
|
+
"hono": ">=4.12.12",
|
|
19
20
|
"tsdown": "0.21.10",
|
|
20
21
|
"typescript": "^6.0.3",
|
|
21
22
|
"vitest": "^4.1.5"
|