@onboardbase/cli
Version:
[](https://www.npmjs.com/package/@onboardbase/cli) [](https://www.npmjs.com/package/@onboardbase/cli) [ • 3.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.changeCommandVisibility = exports.saveProject = exports.getAllProjects = exports.getCommandProjectId = exports.deleteCommand = exports.getAllCommands = exports.saveCommands = void 0;
const config_1 = require("../configuration/config");
const chalk = require("chalk");
const http_1 = require("../http");
const genericAPIRequest = async (query) => {
const { accessToken } = await (0, http_1.generateAccessToken)(await config_1.default.getToken());
const instance = config_1.default.getHttpInstance("https://devcommandapi.onboardbase.com/graphql");
instance.defaults.headers["Authorization"] = `Bearer ${accessToken}`;
const { data } = await instance.post("", { query });
if (data.errors) {
if (data.errors[0].message === "Unauthorized") {
console.error(chalk.red("Sorry you don't have access token to save commands, please initiate login from cli"));
process.exit(1);
}
console.error(chalk.bold.red(data.errors[0].message));
process.exit(1);
}
return data;
};
const saveCommands = async ({ name, commandList, executor, description, projectName, mode }) => {
const query = `mutation {
createCommand(
createCommandInput: {
name: "${name}",
executor: "${executor}",
commandList: "${commandList}",
description: "${description}",
projectName: "${projectName}",
mode: "${mode}"
}){
id
name
commandList
executor
description
}
}
`;
return genericAPIRequest(query);
};
exports.saveCommands = saveCommands;
const getAllCommands = async () => {
const query = `
query {
commands {
id
name
mode
commandList
executor
description
}
}
`;
return genericAPIRequest(query);
};
exports.getAllCommands = getAllCommands;
const deleteCommand = async (commandId) => {
const query = `
query {
removeCommand(id: "${commandId}"){
id
name
commandList
executor
description
}
}
`;
return genericAPIRequest(query);
};
exports.deleteCommand = deleteCommand;
const getCommandProjectId = async (name) => {
const query = `
query {
projects(filterOptions: {name: "${name}"}){
id
}
}
`;
return genericAPIRequest(query);
};
exports.getCommandProjectId = getCommandProjectId;
const getAllProjects = async () => {
const query = `
query {
projects{
id
name
description
}
}
`;
return genericAPIRequest(query);
};
exports.getAllProjects = getAllProjects;
const saveProject = async ({ name, description, }) => {
const query = `mutation {
createProject(
createProjectInput: {
name: "${name}",
description: "${description}",
}){
id
name
description
}
}
`;
return genericAPIRequest(query);
};
exports.saveProject = saveProject;
const changeCommandVisibility = async (command) => {
const query = `mutation {
changeCommandVisibility (
command: "${command}",
fromCli: true
)
{
status
message
}
}
`;
return genericAPIRequest(query);
};
exports.changeCommandVisibility = changeCommandVisibility;