zcatalyst-cli
Version:
Command Line Tool for CATALYST
56 lines (55 loc) • 2.94 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getData = exports.sourceId = void 0;
const ansi_colors_1 = require("ansi-colors");
const moment_1 = __importDefault(require("moment"));
const endpoints_1 = require("../endpoints");
const index_js_1 = __importDefault(require("../error/index.js"));
const js_1 = require("../util_modules/js");
exports.sourceId = 'NULL';
function getData(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const segmentId = options.segment;
const allSegments = (yield (yield (0, endpoints_1.cacheAPI)()).getAllSegments());
const selectedSegment = segmentId !== undefined
? allSegments.find((segment) => segment.segment_name === segmentId || segment.id + '' === segmentId)
: allSegments.find((segment) => segment.segment_name === 'Default');
if (selectedSegment === undefined) {
if (!allSegments.find((segment) => segment.segment_name === 'Default')) {
throw new index_js_1.default('Default segment is missing !!!', { exit: 2 });
}
throw new index_js_1.default('Unknown segment identifier', {
exit: 1,
errorId: 'CACHE-1',
arg: [(0, ansi_colors_1.bold)(segmentId || ''), (0, ansi_colors_1.bold)('--segment')]
});
}
exports.sourceId = selectedSegment.id;
const expiryInHours = js_1.JS.random(1, 48);
return {
cache_name: js_1.JS.randomString(js_1.JS.random(5, 10)),
cache_value: js_1.JS.randomString(10),
project_details: selectedSegment.project_details,
segment_details: {
segment_name: selectedSegment.segment_name,
id: selectedSegment.id
},
expiry_in_hours: expiryInHours,
expires_in: (0, moment_1.default)(moment_1.default.now() + expiryInHours * 60 * 60 * 1000).format('MMM DD, YYYY hh:mm A'),
ttl_in_milliseconds: expiryInHours * 60 * 60 * 1000 + ''
};
});
}
exports.getData = getData;