UNPKG

@haechi-labs/henesis-cli

Version:

🚀 Command Line Interface tool to Utilize henesis

119 lines • 3.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../types"); const class_transformer_1 = require("class-transformer"); const url_1 = require("./url"); const wretch_1 = require("./wretch"); const Integration_1 = require("../types/Integration"); class IntegrationRpc { constructor(server, version) { this.server = server + '/integrations/' + version; } async getIntegrationUsage(integrationId, startDate, endDate) { let json = await wretch_1.getWretcher() .url(`${this.server}/${integrationId}/stats?start=${startDate}&end=${endDate}`) .get() .error(404, err => { throw new Error('integration does not exist'); }) .json() .catch((err) => { throw err; }); return class_transformer_1.plainToClass(Integration_1.IntegrationStat, json); } /** * Gets a list of integrations. * @returns A list of integrations */ async getIntegrations() { const json = await wretch_1.getWretcher() .url(this.server) .get() .json() .catch((err) => { throw err; }); if (!Array.isArray(json)) { throw new Error(`Expected getIntegrationsList to return an array but it returned ${json}`); } return class_transformer_1.plainToClass(types_1.Integration, json); } /** * find a integrations by name. * @returns a integration */ async getIntegrationByName(name) { const json = await wretch_1.getWretcher() .url(this.server + '/findByName') .query({ name: name }) .get() .json() .catch((err) => { throw err; }); return class_transformer_1.plainToClass(types_1.Integration, json); } /** * Get a integration. * @returns A integration */ async getIntegration(integrationId) { const json = await wretch_1.getWretcher() .url(this.server + '/' + integrationId) .get() .json() .catch((err) => { throw err; }); return class_transformer_1.plainToClass(types_1.Integration, json); } /** * Patch a integration. * @returns A integration */ async updateIntegration(integrationId, updateIntegrationRequest) { const json = await wretch_1.getWretcher() .url(this.server + '/' + integrationId) .put(updateIntegrationRequest) .json() .catch((err) => { throw err; }); return class_transformer_1.plainToClass(types_1.Integration, json); } /** * Create a integration. * @returns A integration */ async createIntegration(request) { const json = await wretch_1.getWretcher() .url(this.server) .post(request) .json() .catch((err) => { throw err; }); return class_transformer_1.plainToClass(types_1.Integration, json); } /** * Create a integration. * @returns A integration */ async deleteIntegration(integrationId) { await wretch_1.getWretcher() .url(this.server + '/' + integrationId) .delete() .text() .catch((err) => { throw err; }); return null; } } exports.IntegrationRpc = IntegrationRpc; // @ts-ignore const url = url_1.baseUrl(); const integrationRpc = new IntegrationRpc(url, url_1.rpcVersion); exports.default = integrationRpc; //# sourceMappingURL=integration.js.map