@baruchiro/paperless-mcp
Version:
Model Context Protocol (MCP) server for interacting with Paperless-NGX document management system. Enables AI assistants to manage documents, tags, correspondents, and document types through the Paperless-NGX API.
35 lines (34 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMonetaryValidationError = getMonetaryValidationError;
exports.validateCustomFields = validateCustomFields;
const SYMBOL_TO_CODE = {
$: "USD",
"€": "EUR",
"£": "GBP",
"¥": "JPY",
"₹": "INR",
"₪": "ILS",
};
const TRAILING_SYMBOL_REGEX = new RegExp(`^(\\d+(?:\\.\\d+)?)[${Object.keys(SYMBOL_TO_CODE).join("")}]$`);
function getMonetaryValidationError(value) {
const trailingMatch = TRAILING_SYMBOL_REGEX.exec(value);
if (trailingMatch) {
const amount = trailingMatch[1];
const symbol = value.slice(-1);
const code = SYMBOL_TO_CODE[symbol] || "USD";
const numericAmount = parseFloat(amount);
const formattedAmount = isNaN(numericAmount) ? amount : numericAmount.toFixed(2);
return (`Invalid monetary format "${value}". ` +
`Paperless-NGX requires the currency code as a prefix, e.g. "${code}${formattedAmount}". ` +
`Use the format: {CURRENCY_CODE}{amount} (e.g., USD10.00, GBP123.45, EUR9.99).`);
}
return null;
}
function validateCustomFields(custom_fields) {
custom_fields === null || custom_fields === void 0 ? void 0 : custom_fields.filter((cf) => typeof cf.value === "string").forEach((cf) => {
const monetaryError = getMonetaryValidationError(cf.value);
if (monetaryError)
throw new Error(monetaryError);
});
}