Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m14s
CI/CD Pipeline / Security Scanning (push) Successful in 2m20s
CI/CD Pipeline / Lint and Format (push) Failing after 44s
CI/CD Pipeline / Terraform Validation (push) Failing after 23s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 24s
HYBX OMNL TypeScript & anchor / token-aggregation build + reconcile artifact (push) Failing after 25s
Validation / validate-genesis (push) Successful in 26s
Validation / validate-terraform (push) Failing after 23s
Validation / validate-kubernetes (push) Failing after 8s
Validation / validate-smart-contracts (push) Failing after 9s
Validation / validate-security (push) Failing after 1m13s
Validation / validate-documentation (push) Failing after 17s
OMNL reconcile anchor / Run omnl:reconcile and upload artifacts (push) Failing after 28s
Verify Deployment / Verify Deployment (push) Failing after 1m18s
Update checkpoint-core ISO20022 types/hashes, swift-listener canonical mapping, and chain138 address inventory. Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/**
|
|
* Telex transport adapter — dry-run email-to-telex normalization for KTT rail.
|
|
* Usage: node dist/cli.js [--dry-run] <raw-file>
|
|
*/
|
|
import { readFileSync } from 'fs';
|
|
|
|
function extractTelexFromEmail(payload: string): string {
|
|
const text = payload.trim();
|
|
if (text.startsWith('{') && text.includes('body')) {
|
|
try {
|
|
const obj = JSON.parse(text) as Record<string, unknown>;
|
|
return String(obj.body ?? obj.text ?? text);
|
|
} catch {
|
|
/* continue */
|
|
}
|
|
}
|
|
const parts = text.split(/\n\n/);
|
|
if (parts.length >= 2 && /^From:/m.test(text)) return parts.slice(1).join('\n\n').trim();
|
|
return text;
|
|
}
|
|
|
|
function parseFields(body: string): Record<string, string> {
|
|
const fields: Record<string, string> = {};
|
|
for (const line of body.split('\n')) {
|
|
const upper = line.toUpperCase();
|
|
if (upper.startsWith('ORDERING:')) fields.debtorId = line.split(':').slice(1).join(':').trim();
|
|
if (upper.startsWith('BENEFICIARY:')) fields.creditorId = line.split(':').slice(1).join(':').trim();
|
|
if (upper.startsWith('AMOUNT:')) {
|
|
const p = line.split(':').slice(1).join(':').trim().split(/\s+/);
|
|
if (p.length >= 2) {
|
|
fields.currencyCode = p[0];
|
|
fields.amount = p[1];
|
|
}
|
|
}
|
|
}
|
|
return fields;
|
|
}
|
|
|
|
const dryRun = process.argv.includes('--dry-run') || process.env.TELEX_TRANSPORT_DRY_RUN === '1';
|
|
const file = process.argv.find((a) => !a.startsWith('-') && a !== process.argv[0] && a !== process.argv[1]);
|
|
const raw = file ? readFileSync(file, 'utf8') : readFileSync(0, 'utf8');
|
|
const normalizedBody = extractTelexFromEmail(raw);
|
|
const messageType = normalizedBody.includes(':20:') ? 'TELEX_KTT' : 'KTT';
|
|
|
|
console.log(
|
|
JSON.stringify({
|
|
dryRun,
|
|
format: 'ktt',
|
|
messageType,
|
|
normalizedBody,
|
|
normalizedFields: parseFields(normalizedBody),
|
|
})
|
|
);
|