@pedily/extension-scripts
Version:
Utility that helps creating Extensions for the Cognigy.AI platform
55 lines (54 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateExtension = exports.uploadExtension = exports.getExtensions = void 0;
const promises_1 = require("fs/promises");
const path_1 = require("path");
const getExtensions = async (params) => {
const { apiKey, apiBaseUrl, projectId } = params;
const url = `${apiBaseUrl}/new/v2.0/extensions?projectId=${projectId}`;
const response = await fetch(url, {
method: "GET",
headers: {
"x-api-key": apiKey,
},
});
return (await response.json())._embedded.extensions;
};
exports.getExtensions = getExtensions;
const uploadExtension = async (params) => {
const { apiKey, apiBaseUrl, filePath, projectId } = params;
const extensionFileName = (0, path_1.basename)(filePath, (0, path_1.extname)(filePath));
const extensionBlob = new Blob([await (0, promises_1.readFile)(filePath)]);
const body = new FormData();
body.set("projectId", projectId);
body.set("file", extensionBlob, extensionFileName);
const url = `${apiBaseUrl}/new/v2.0/extensions/upload`;
const response = await fetch(url, {
method: "POST",
headers: {
"x-api-key": apiKey,
},
body,
});
console.log(await response.json());
};
exports.uploadExtension = uploadExtension;
const updateExtension = async (params) => {
const { apiKey, apiBaseUrl, filePath, projectId, extensionId } = params;
const extensionFileName = (0, path_1.basename)(filePath, (0, path_1.extname)(filePath));
const extensionBlob = new Blob([await (0, promises_1.readFile)(filePath)]);
const body = new FormData();
body.set("projectId", projectId);
body.set("extension", extensionId);
body.set("file", extensionBlob, extensionFileName);
const url = `${apiBaseUrl}/new/v2.0/extensions/update`;
const response = await fetch(url, {
method: "POST",
headers: {
"x-api-key": apiKey,
},
body,
});
console.log(await response.json());
};
exports.updateExtension = updateExtension;