@clipwhisperer/common
Version:
ClipWhisperer Common - Shared library providing core utilities, database schemas, authentication, bucket management, and common functionality across all ClipWhisperer microservices
34 lines (33 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createVaultClient = exports.VaultClient = void 0;
class VaultClient {
constructor(config) {
this.config = config;
}
async readSecret(path, schema) {
var _a, _b;
const url = `${this.config.address}/v1/${path}`;
const res = await fetch(url, {
headers: {
"X-Vault-Token": this.config.token,
},
});
if (!res.ok) {
throw new Error(`Vault request failed with status ${res.status}`);
}
const body = await res.json();
const data = (_b = (_a = body.data) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : body.data;
return schema.parse(data);
}
}
exports.VaultClient = VaultClient;
const createVaultClient = () => {
const address = process.env.VAULT_ADDR;
const token = process.env.VAULT_TOKEN;
if (!address || !token) {
throw new Error("Vault configuration is missing");
}
return new VaultClient({ address, token });
};
exports.createVaultClient = createVaultClient;