@prismatic-io/embedded
Version:
Embed Prismatic's integration marketplace and workflow designer within your existing application.
38 lines (37 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPrismaticUrl = exports.getPrismAccessToken = void 0;
const node_child_process_1 = require("node:child_process");
const node_util_1 = require("node:util");
const exec = (0, node_util_1.promisify)(node_child_process_1.exec);
const isPrismAvailable = async () => {
try {
await exec("prism --version", { windowsHide: true });
return true;
}
catch {
return false;
}
};
const getPrismAccessToken = async () => {
if (!(await isPrismAvailable())) {
throw new Error("Prism CLI must be installed. Please install it globally and run 'prism login' to authenticate.");
}
try {
const { stdout } = await exec("prism me:token", { windowsHide: true });
const accessToken = stdout.replace(/\n$/, "").trim();
if (!accessToken) {
throw new Error("Failed to get access token. Please run 'prism login' to authenticate.");
}
return accessToken;
}
catch (error) {
if (error instanceof Error && error.message.includes("command not found")) {
throw new Error("Prism CLI not found. Please install it globally.");
}
throw new Error(`Failed to get access token: ${error instanceof Error ? error.message : String(error)}`);
}
};
exports.getPrismAccessToken = getPrismAccessToken;
const getPrismaticUrl = () => process.env.PRISMATIC_URL ?? "https://app.prismatic.io";
exports.getPrismaticUrl = getPrismaticUrl;