superjolt
Version:
AI-powered deployment platform with MCP support - Deploy JavaScript apps using natural language with Claude Desktop
189 lines • 6.82 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var StorageService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageService = void 0;
const common_1 = require("@nestjs/common");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const SERVICE_NAME = 'superjolt-cli';
let StorageService = StorageService_1 = class StorageService {
logger = new common_1.Logger(StorageService_1.name);
configDir = path.join(os.homedir(), '.config', 'superjolt');
keytarAvailable = null;
keytar = null;
constructor() {
this.ensureConfigDir();
}
async loadKeytar() {
if (this.keytarAvailable !== null) {
return this.keytarAvailable;
}
try {
this.keytar = require('keytar');
this.keytarAvailable = true;
return true;
}
catch {
this.keytarAvailable = false;
return false;
}
}
async get(key, options = {}) {
if (options.secure && (await this.loadKeytar())) {
try {
const value = await this.keytar.getPassword(SERVICE_NAME, key);
if (value) {
return value;
}
}
catch (error) {
this.logger.debug(`Failed to get secure value for ${key}:`, error);
}
}
const filePath = this.getFilePath(key);
if (fs.existsSync(filePath)) {
try {
const content = fs.readFileSync(filePath, 'utf-8').trim();
return content;
}
catch (error) {
this.logger.debug(`Failed to read file for ${key}:`, error);
}
}
return null;
}
async set(key, value, options = {}) {
if (options.secure && (await this.loadKeytar())) {
try {
await this.keytar.setPassword(SERVICE_NAME, key, value);
const filePath = this.getFilePath(key);
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
return;
}
catch (error) {
this.logger.debug(`Failed to set secure value for ${key}:`, error);
}
}
const filePath = this.getFilePath(key);
fs.writeFileSync(filePath, value, {
encoding: 'utf-8',
mode: options.secure ? 0o600 : 0o644,
});
}
async delete(key, options = {}) {
if (options.secure && (await this.loadKeytar())) {
try {
await this.keytar.deletePassword(SERVICE_NAME, key);
}
catch {
}
}
const filePath = this.getFilePath(key);
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
}
async getJson(key) {
const value = await this.get(key);
if (!value)
return null;
try {
return JSON.parse(value);
}
catch (error) {
this.logger.debug(`Failed to parse JSON for ${key}:`, error);
return null;
}
}
async setJson(key, data) {
const value = JSON.stringify(data, null, 2);
await this.set(key, value);
}
async exists(key, options = {}) {
const value = await this.get(key, options);
return value !== null;
}
listKeys() {
if (!fs.existsSync(this.configDir)) {
return [];
}
try {
const files = fs.readdirSync(this.configDir);
return files.filter((file) => !file.startsWith('.'));
}
catch {
return [];
}
}
async clearAll() {
if (fs.existsSync(this.configDir)) {
const files = fs.readdirSync(this.configDir);
for (const file of files) {
if (!file.startsWith('.')) {
fs.unlinkSync(path.join(this.configDir, file));
}
}
}
this.logger.warn('Cleared all file storage (keytar storage unchanged)');
}
getFilePath(key) {
const safeKey = key.replace(/[^a-zA-Z0-9-_]/g, '_');
return path.join(this.configDir, safeKey);
}
ensureConfigDir() {
if (!fs.existsSync(this.configDir)) {
fs.mkdirSync(this.configDir, { recursive: true });
}
}
};
exports.StorageService = StorageService;
exports.StorageService = StorageService = StorageService_1 = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [])
], StorageService);
//# sourceMappingURL=storage.service.js.map