@iota-big3/sdk-gateway
Version:
Universal API Gateway with protocol translation, intelligent routing, rate limiting, health checking, and caching
225 lines • 7.64 kB
JavaScript
;
/**
* Financial Sector Type Definitions
* Following Phase 2g: Strict types for financial operations
*
* @module financial-types
* @description Provides type-safe financial operations with:
* - Decimal precision (no floating point errors)
* - Immutable transaction records
* - Double-entry bookkeeping constraints
* - Currency handling
* - Audit trail support
* - SOX/Financial compliance
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.financialTypes = exports.FinancialPermission = exports.AuditAction = exports.JournalEntryStatus = exports.EntryType = exports.AccountType = void 0;
exports.isBalanceSheetAccount = isBalanceSheetAccount;
exports.isIncomeStatementAccount = isIncomeStatementAccount;
exports.getNormalBalance = getNormalBalance;
exports.addMoney = addMoney;
exports.subtractMoney = subtractMoney;
exports.formatMoney = formatMoney;
// ============================================
// General Ledger Types
// ============================================
/**
* Chart of Accounts - Account Types
* Based on standard accounting principles
*/
var AccountType;
(function (AccountType) {
// Balance Sheet Accounts
AccountType["Asset"] = "ASSET";
AccountType["Liability"] = "LIABILITY";
AccountType["Equity"] = "EQUITY";
// Income Statement Accounts
AccountType["Revenue"] = "REVENUE";
AccountType["Expense"] = "EXPENSE";
// Special Types
AccountType["ContraAsset"] = "CONTRA_ASSET";
AccountType["ContraLiability"] = "CONTRA_LIABILITY";
AccountType["ContraEquity"] = "CONTRA_EQUITY";
AccountType["ContraRevenue"] = "CONTRA_REVENUE";
AccountType["ContraExpense"] = "CONTRA_EXPENSE";
})(AccountType || (exports.AccountType = AccountType = {}));
/**
* Debit or Credit side of a transaction
*/
var EntryType;
(function (EntryType) {
EntryType["Debit"] = "DEBIT";
EntryType["Credit"] = "CREDIT";
})(EntryType || (exports.EntryType = EntryType = {}));
/**
* Journal Entry Status - Workflow states
*/
var JournalEntryStatus;
(function (JournalEntryStatus) {
JournalEntryStatus["Draft"] = "DRAFT";
JournalEntryStatus["PendingApproval"] = "PENDING_APPROVAL";
JournalEntryStatus["Approved"] = "APPROVED";
JournalEntryStatus["Posted"] = "POSTED";
JournalEntryStatus["Reversed"] = "REVERSED";
JournalEntryStatus["Rejected"] = "REJECTED";
})(JournalEntryStatus || (exports.JournalEntryStatus = JournalEntryStatus = {}));
var AuditAction;
(function (AuditAction) {
AuditAction["Create"] = "CREATE";
AuditAction["Update"] = "UPDATE";
AuditAction["Delete"] = "DELETE";
AuditAction["Approve"] = "APPROVE";
AuditAction["Reject"] = "REJECT";
AuditAction["Post"] = "POST";
AuditAction["Reverse"] = "REVERSE";
AuditAction["Export"] = "EXPORT";
AuditAction["View"] = "VIEW";
})(AuditAction || (exports.AuditAction = AuditAction = {}));
var FinancialPermission;
(function (FinancialPermission) {
// View permissions
FinancialPermission["ViewJournalEntries"] = "VIEW_JOURNAL_ENTRIES";
FinancialPermission["ViewTrialBalance"] = "VIEW_TRIAL_BALANCE";
FinancialPermission["ViewFinancialReports"] = "VIEW_FINANCIAL_REPORTS";
FinancialPermission["ViewAuditTrail"] = "VIEW_AUDIT_TRAIL";
// Create permissions
FinancialPermission["CreateJournalEntry"] = "CREATE_JOURNAL_ENTRY";
FinancialPermission["CreateAccount"] = "CREATE_ACCOUNT";
// Modify permissions
FinancialPermission["EditDraftEntry"] = "EDIT_DRAFT_ENTRY";
FinancialPermission["PostJournalEntry"] = "POST_JOURNAL_ENTRY";
FinancialPermission["ReverseJournalEntry"] = "REVERSE_JOURNAL_ENTRY";
// Approval permissions
FinancialPermission["ApproveJournalEntry"] = "APPROVE_JOURNAL_ENTRY";
FinancialPermission["ApproveNewAccount"] = "APPROVE_NEW_ACCOUNT";
// Period management
FinancialPermission["ClosePeriod"] = "CLOSE_PERIOD";
FinancialPermission["ReopenPeriod"] = "REOPEN_PERIOD";
// Admin permissions
FinancialPermission["ManageChartOfAccounts"] = "MANAGE_CHART_OF_ACCOUNTS";
FinancialPermission["ManageUsers"] = "MANAGE_USERS";
FinancialPermission["ExportData"] = "EXPORT_DATA";
})(FinancialPermission || (exports.FinancialPermission = FinancialPermission = {}));
// ============================================
// Type Guards
// ============================================
/**
* Check if account is a balance sheet account
*/
function isBalanceSheetAccount(type) {
return [
AccountType.Asset,
AccountType.Liability,
AccountType.Equity,
AccountType.ContraAsset,
AccountType.ContraLiability,
AccountType.ContraEquity
].includes(type);
}
/**
* Check if account is an income statement account
*/
function isIncomeStatementAccount(type) {
return [
AccountType.Revenue,
AccountType.Expense,
AccountType.ContraRevenue,
AccountType.ContraExpense
].includes(type);
}
/**
* Get normal balance for account type
*/
function getNormalBalance(type) {
switch (type) {
case AccountType.Asset:
case AccountType.Expense:
case AccountType.ContraLiability:
case AccountType.ContraEquity:
case AccountType.ContraRevenue:
return 'DEBIT';
case AccountType.Liability:
case AccountType.Equity:
case AccountType.Revenue:
case AccountType.ContraAsset:
case AccountType.ContraExpense:
return 'CREDIT';
}
}
// ============================================
// Financial Calculations
// ============================================
/**
* Add two monetary amounts (must be same currency)
*/
function addMoney(a, b) {
if (a.currency !== b.currency) {
return {
success: false,
error: new Error(`Cannot add different currencies: ${a.currency} and ${b.currency}`)
};
}
if (a.precision !== b.precision) {
return {
success: false,
error: new Error(`Precision mismatch: ${a.precision} and ${b.precision}`)
};
}
return {
success: true,
data: {
value: a.value + b.value,
precision: a.precision,
currency: a.currency
}
};
}
/**
* Subtract monetary amounts (must be same currency)
*/
function subtractMoney(a, b) {
if (a.currency !== b.currency) {
return {
success: false,
error: new Error(`Cannot subtract different currencies: ${a.currency} and ${b.currency}`)
};
}
if (a.precision !== b.precision) {
return {
success: false,
error: new Error(`Precision mismatch: ${a.precision} and ${b.precision}`)
};
}
return {
success: true,
data: {
value: a.value - b.value,
precision: a.precision,
currency: a.currency
}
};
}
/**
* Format monetary amount for display
*/
function formatMoney(amount) {
const divisor = BigInt(10 ** amount.precision);
const whole = amount.value / divisor;
const fraction = amount.value % divisor;
const fractionStr = fraction.toString().padStart(amount.precision, '0');
return `${amount.currency} ${whole}.${fractionStr}`;
}
// ============================================
// Export Financial Types
// ============================================
exports.financialTypes = {
// Type guards
isBalanceSheetAccount,
isIncomeStatementAccount,
getNormalBalance,
// Calculations
addMoney,
subtractMoney,
formatMoney
};
//# sourceMappingURL=financial-types.js.map