Skip to content

Commit efa14af

Browse files
authored
feat: add getGatewaySkill method to Node SDK (#26)
1 parent ea0cc17 commit efa14af

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export class OneCLI {
4343
this.provisionClient = new ProvisionClient(url, apiKey, timeout);
4444
}
4545

46+
/**
47+
* Fetch the gateway skill markdown from OneCLI.
48+
*/
49+
getGatewaySkill = (): Promise<string> => {
50+
return this.containerClient.getGatewaySkill();
51+
};
52+
4653
/**
4754
* Fetch the raw container configuration from OneCLI.
4855
*/

src/container/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ export class ContainerClient {
1313
this.timeout = timeout;
1414
}
1515

16+
/**
17+
* Fetch the gateway skill markdown from OneCLI.
18+
*/
19+
getGatewaySkill = async (): Promise<string> => {
20+
const url = `${this.baseUrl}/api/skill/gateway`;
21+
try {
22+
const headers: Record<string, string> = {};
23+
if (this.apiKey) {
24+
headers["Authorization"] = `Bearer ${this.apiKey}`;
25+
}
26+
27+
const res = await fetch(url, {
28+
headers,
29+
signal: AbortSignal.timeout(this.timeout),
30+
});
31+
32+
if (!res.ok) {
33+
throw new OneCLIRequestError(
34+
`OneCLI returned ${res.status} ${res.statusText}`,
35+
{ url, statusCode: res.status },
36+
);
37+
}
38+
39+
return await res.text();
40+
} catch (error) {
41+
if (
42+
error instanceof OneCLIError ||
43+
error instanceof OneCLIRequestError
44+
) {
45+
throw error;
46+
}
47+
throw toOneCLIError(error);
48+
}
49+
};
50+
1651
/**
1752
* Fetch the raw container configuration from OneCLI.
1853
*/

0 commit comments

Comments
 (0)