@prismatic-io/spectral
Version:
Utility library for building Prismatic connectors and code-native integrations
65 lines (64 loc) • 2.9 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getComponentSignatureWithPrism = exports.getPrismAccessToken = void 0;
const child_process_1 = require("child_process");
const util_1 = require("util");
const exec = (0, util_1.promisify)(child_process_1.exec);
const isPrismAvailable = () => __awaiter(void 0, void 0, void 0, function* () {
try {
yield exec("prism --version", {
windowsHide: true,
});
}
catch (_a) {
return false;
}
return true;
});
const getPrismAccessToken = () => __awaiter(void 0, void 0, void 0, function* () {
if (!(yield isPrismAvailable())) {
throw new Error("Prism CLI must be installed. Please install it globally and run 'prism login' to authenticate.");
}
try {
const { stdout } = yield 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 getComponentSignatureWithPrism = (_a) => __awaiter(void 0, [_a], void 0, function* ({ skipSignatureVerify, }) {
if (!(yield isPrismAvailable())) {
console.log("Prism must be installed.");
process.exit(1);
}
const { stdout } = yield exec(`prism components:signature ${skipSignatureVerify ? "--skip-signature-verify" : ""}`, {
windowsHide: true,
});
const signatureKey = stdout.replace(/\n$/, "");
if (!signatureKey) {
console.log("Failed to get component signature, please verify your component has been published.");
process.exit(1);
}
return signatureKey;
});
exports.getComponentSignatureWithPrism = getComponentSignatureWithPrism;