sesterce-cli
Version:
A powerful command-line interface tool for managing Sesterce Cloud services. Sesterce CLI provides easy access to GPU cloud instances, AI inference services, container registries, and SSH key management directly from your terminal.
63 lines • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiClientProvider = void 0;
const get_api_key_1 = require("@/access/get-api-key");
function isStandardApiError(error) {
return "statusCode" in error && "message" in error;
}
class _ApiClientProvider {
constructor() {
this.client = fetch;
this.baseUrl = "https://api.cloud.sesterce.com";
this.apiKey = (0, get_api_key_1.getApiKey)();
}
async request(path, init) {
const response = await this.client(`${this.baseUrl}${path}`, {
...init,
headers: {
...init === null || init === void 0 ? void 0 : init.headers,
"x-api-key": this.apiKey,
},
});
if (!response.ok) {
const error = await response.json();
if (isStandardApiError(error)) {
throw new Error(error.message);
}
throw new Error("Unexpected error occurred.");
}
if (response.status === 204) {
return null;
}
return response.json();
}
async get(path, init) {
return this.request(path, {
...init,
method: "GET",
});
}
async post(path, init) {
return this.request(path, {
...init,
method: "POST",
headers: (init === null || init === void 0 ? void 0 : init.body)
? { ...init === null || init === void 0 ? void 0 : init.headers, "Content-Type": "application/json" }
: init === null || init === void 0 ? void 0 : init.headers,
});
}
async patch(path, init) {
return this.request(path, {
...init,
method: "PATCH",
headers: (init === null || init === void 0 ? void 0 : init.body)
? { ...init === null || init === void 0 ? void 0 : init.headers, "Content-Type": "application/json" }
: init === null || init === void 0 ? void 0 : init.headers,
});
}
async delete(path, init) {
return this.request(path, { ...init, method: "DELETE" });
}
}
exports.apiClientProvider = new _ApiClientProvider();
//# sourceMappingURL=api-client-provider.js.map