diff --git a/src/client.ts b/src/client.ts index fd8db55..98eb7de 100644 --- a/src/client.ts +++ b/src/client.ts @@ -43,6 +43,13 @@ export class OneCLI { this.provisionClient = new ProvisionClient(url, apiKey, timeout); } + /** + * Fetch the gateway skill markdown from OneCLI. + */ + getGatewaySkill = (): Promise => { + return this.containerClient.getGatewaySkill(); + }; + /** * Fetch the raw container configuration from OneCLI. */ diff --git a/src/container/index.ts b/src/container/index.ts index 0e34c52..34d611d 100644 --- a/src/container/index.ts +++ b/src/container/index.ts @@ -13,6 +13,41 @@ export class ContainerClient { this.timeout = timeout; } + /** + * Fetch the gateway skill markdown from OneCLI. + */ + getGatewaySkill = async (): Promise => { + const url = `${this.baseUrl}/api/skill/gateway`; + try { + const headers: Record = {}; + if (this.apiKey) { + headers["Authorization"] = `Bearer ${this.apiKey}`; + } + + const res = await fetch(url, { + headers, + signal: AbortSignal.timeout(this.timeout), + }); + + if (!res.ok) { + throw new OneCLIRequestError( + `OneCLI returned ${res.status} ${res.statusText}`, + { url, statusCode: res.status }, + ); + } + + return await res.text(); + } catch (error) { + if ( + error instanceof OneCLIError || + error instanceof OneCLIRequestError + ) { + throw error; + } + throw toOneCLIError(error); + } + }; + /** * Fetch the raw container configuration from OneCLI. */