@event-inc/pipelines
Version:
Event Inc is a fully managed event bus lets you send and receive data across mission-critical cloud apps, databases and warehouses.
102 lines • 5.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listPipelinesApi = exports.deletePipelineApi = exports.updatePipelineApi = exports.createPipelineApi = void 0;
const tslib_1 = require("tslib");
const utils_1 = require("@event-inc/utils");
const utilities_1 = require("./utilities");
const ramda_1 = require("ramda");
const utils_2 = require("@event-inc/utils");
const configs_apis_1 = require("./configs.apis");
const createPipelineApi = (headers, url, payload) => {
const { label, key, source, destination, settings, extractors, transformation, } = payload;
(0, utils_1.checkIfKeyOrIdExists)(source === null || source === void 0 ? void 0 : source.id, source === null || source === void 0 ? void 0 : source.key, 'Must provide either source key or id for pipeline creation');
(0, utils_1.checkIfKeyOrIdExists)(destination === null || destination === void 0 ? void 0 : destination.id, destination === null || destination === void 0 ? void 0 : destination.key, 'Must provide either destination key or id for pipeline creation');
const finalPayload = {
key,
name: label,
source: {
events: source.events,
key: source === null || source === void 0 ? void 0 : source.key,
id: source === null || source === void 0 ? void 0 : source.id,
},
destinations: [
{
action: destination.action,
key: destination.key,
id: destination === null || destination === void 0 ? void 0 : destination.id,
},
],
config: (0, utilities_1.getConfig)(settings),
middleware: (0, utilities_1.getMiddleware)(extractors, transformation),
};
return (0, utils_1.makeHttpNetworkCall)({
method: 'POST',
url: `${url}/${configs_apis_1.version3}/pipelines/create`,
data: finalPayload,
headers,
});
};
exports.createPipelineApi = createPipelineApi;
const updatePipelineApi = (headers, url, payload) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
const { key, id, source, destination, settings, extractors, transformation, active, } = payload;
(0, utils_1.checkIfKeyOrIdExists)(payload === null || payload === void 0 ? void 0 : payload.id, payload === null || payload === void 0 ? void 0 : payload.key, 'Must provide either pipeline key or id for updating a pipeline');
if (source)
(0, utils_1.checkIfKeyOrIdExists)(source === null || source === void 0 ? void 0 : source.id, source === null || source === void 0 ? void 0 : source.key, 'Must provide either source key or id for updating a pipeline');
if (destination)
(0, utils_1.checkIfKeyOrIdExists)(destination === null || destination === void 0 ? void 0 : destination.id, destination === null || destination === void 0 ? void 0 : destination.key, 'Must provide either destination key or id for updating a pipeline');
const updateUrl = `${url}/${configs_apis_1.version3}/pipelines/update`;
const pipeline = yield (0, exports.listPipelinesApi)(headers, url, {
query: {
key,
_id: id,
},
});
const { data } = (0, utils_2.matchResultAndHandleHttpError)(pipeline, ramda_1.identity);
const finalPayload = {
id,
key,
active,
source: source && {
events: source.events,
key: source.key,
id: source.id,
},
destinations: destination && [
{
action: destination.action,
key: destination.key,
id: destination.id,
},
],
config: settings && (0, utilities_1.getConfig)(settings, (_a = data === null || data === void 0 ? void 0 : data.rows) === null || _a === void 0 ? void 0 : _a[0]),
middleware: (0, utilities_1.getMiddleware)(extractors, transformation, (_c = (_b = data === null || data === void 0 ? void 0 : data.rows) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.middleware)
};
return (0, utils_1.makeHttpNetworkCall)({
method: 'POST',
url: updateUrl,
data: finalPayload,
headers,
});
});
exports.updatePipelineApi = updatePipelineApi;
const deletePipelineApi = (headers, url, payload) => {
(0, utils_1.checkIfKeyOrIdExists)(payload === null || payload === void 0 ? void 0 : payload.id, payload === null || payload === void 0 ? void 0 : payload.key, 'Must provide either pipeline key or id for deleting a pipeline');
return (0, utils_1.makeHttpNetworkCall)({
method: 'POST',
url: `${url}/${configs_apis_1.version3}/pipelines/delete`,
data: payload,
headers,
});
};
exports.deletePipelineApi = deletePipelineApi;
const listPipelinesApi = (headers, url, payload) => {
return (0, utils_1.makeHttpNetworkCall)({
method: 'POST',
url: `${url}/${configs_apis_1.version3}/pipelines/list`,
data: payload,
headers,
});
};
exports.listPipelinesApi = listPipelinesApi;
//# sourceMappingURL=index.js.map