koneksi-ts-sdk
Version:
A JS/TS SDK for interacting with Koneksi API services
48 lines (47 loc) • 1.96 kB
JavaScript
import { SERVER_CONFIGS } from "./config.js";
import { HttpClient } from "./http-client.js";
import { DirectoryOperations } from "./operations/directories.js";
import { FileOperations } from "./operations/files.js";
import { HealthOperations } from "./operations/health.js";
import { PeersOperations } from "./operations/peers.js";
export class KoneksiSDK {
constructor(config) {
const environment = config.environment || "uat";
if (!SERVER_CONFIGS[environment]) {
throw new Error(`Invalid environment: ${environment}. Valid environments are: ${Object.keys(SERVER_CONFIGS).join(", ")}`);
}
if (!config.client_id || !config.client_secret) {
throw new Error("client_id and client_secret are required");
}
this.httpClient = new HttpClient({
baseURL: SERVER_CONFIGS[environment].apiUrl,
clientId: config.client_id,
clientSecret: config.client_secret,
});
this.directory = new DirectoryOperations(this.httpClient);
this.file = new FileOperations(this.httpClient);
this.health = new HealthOperations(this.httpClient);
this.peers = new PeersOperations(this.httpClient);
}
getConfig() {
return {
environment: this.getEnvironment(),
client_id: this.httpClient["config"].clientId,
client_secret: this.httpClient["config"].clientSecret,
};
}
getEnvironment() {
const baseURL = this.httpClient["config"].baseURL;
for (const [env, config] of Object.entries(SERVER_CONFIGS)) {
if (config.apiUrl === baseURL) {
return env;
}
}
throw new Error("Unable to determine current environment");
}
}
export default KoneksiSDK;
export * from "./types/directories.types.js";
export * from "./types/files.types.js";
export * from "./operations/health.js";
export * from "./operations/peers.js";