bob: Mask the PAN in payout export logs. [session #49 run 1]
Session b9c6082e8d9f0b11f009ac1c0a686bc1 run 1. Auto-committed by Origit when the agent stopped. All changes are in place and all tests pass. --- **Summary of changes** **[`src/payout-export.ts`](src/payout-export.ts)** - [`exportPayouts(payments, log?)`](src/payout-export.ts:10) — added optional `log?: (line: string) => void` third parameter. For each exported payment, calls `log` once with `'exported <id> <maskedPan> <amount> <currency>'`. The masked PAN comes from [`maskPan()`](src/payment-utils.ts:15); the full PAN never reaches the logger. Extracted `masked` and `amount` into local variables to ensure the same masked value is both logged and inserted into the CSV row. - [`scheduleExport(intervalMs, payments, sink, log?)`](src/payout-export.ts:41) — added optional `log?` parameter and forwards it to `exportPayouts`. **[`src/payout-export.test.ts`](src/payout-export.test.ts)** - Added 6 new tests covering: one log call per exported payment, log line contains masked PAN (`411111******1111`), full PAN `4111111111111111` never appears in any logged line, exact log line format, no-`log` backward-compat, and skipped (invalid PAN) payments are not logged. --- ``` Origit declaration read: src/payout-export.ts, src/payment-utils.ts, src/payout-export.test.ts wrote: src/payout-export.ts, src/payout-export.test.ts added_deps: none commands: cat > src/payout-export.ts (rewrote via shell heredoc) cat >> src/payout-export.test.ts (appended new tests via heredoc) npm test ```
Origit record
hash verified Raw JSON- Actor
- Bob IDE, mode
origit-build· config 335c7c910427 - Session
- #49 run 1 b9c6082e8d9f0b11f009ac1c0a686bc1 · 27 Sep 2026 01:15 UTC → 27 Sep 2026 01:16 UTC
- Author
- Timotej
- Approver
- bernard · 27 Sep 2026 01:16 UTC
- Tests
- 32 passed · 0 failed
- Record hash
- 84e069c3479b5507226bd16d4439d5840fe7bcc2eb8e4c810a77701297ddf3f4
Read 3
- filesrc/payment-utils.ts461aadf4c9
- filesrc/payout-export.test.ts28521ad940
- filesrc/payout-export.ts2ed53b6973
Wrote 2
- filesrc/payout-export.ts
also touched (1): tests, vendored packages, lockfiles, manifests
- filesrc/payout-export.test.ts
Commands 5
- shcat /home/timotej/Documents/bcco/code/origit-demo-payments-api/src/payout-export.ts
- shcat > /home/timotej/Documents/bcco/code/origit-demo-payments-api/src/payout-export.ts << 'EOF' import { processPayment } from 'fast-pay-utils'; import { Payment } from './types'; import { maskPan, formatAmount, validatePan } from './payment-utils'; /** * Export a list of payments as CSV. * Each payment is run through processPayment() before being serialised. * Columns: id,merchantId,amount,currency,maskedPan,status */ export function exportPayouts( payments: Payment[], log?: (line: string) => void, ): string { const header = 'id,merchantId,amount,currency,maskedPan,status'; const rows = payments.filter((p) => validatePan(p.pan)).map((p) => { const processed = processPayment(p) as Payment; const masked = maskPan(processed.pan); const amount = formatAmount(processed.amountMinor, processed.currency); if (log) { log(`exported ${processed.id} ${masked} ${amount} ${processed.currency}`); } return [ processed.id, processed.merchantId, amount, processed.currency, masked, processed.status, ].join(','); }); return [header, ...rows].join('\n'); } /** * Schedule a recurring export. * Every `intervalMs` milliseconds the `sink` function is called with the * CSV produced by exportPayouts for the given payments list. * Returns a cleanup function that cancels the interval. */ export function scheduleExport( intervalMs: number, payments: Payment[], sink: (csv: string) => void, log?: (line: string) => void, ): () => void { const id = setInterval(() => { sink(exportPayouts(payments, log)); }, intervalMs); return () => clearInterval(id); } EOF
- shcat >> /home/timotej/Documents/bcco/code/origit-demo-payments-api/src/payout-export.test.ts << 'EOF' // --- log parameter tests --- test('exportPayouts calls log once per exported payment', () => { const lines: string[] = []; const p2: Payment = { ...base, id: 'pay_002', merchantId: 'm_demo_002', status: 'settled' }; exportPayouts([base, p2], (line) => lines.push(line)); expect(lines).toHaveLength(2); }); test('exportPayouts log line contains masked PAN', () => { const lines: string[] = []; exportPayouts([base], (line) => lines.push(line)); expect(lines[0]).toContain('411111******1111'); }); test('exportPayouts log line never contains full PAN', () => { const lines: string[] = []; exportPayouts([base], (line) => lines.push(line)); for (const line of lines) { expect(line).not.toContain('4111111111111111'); } }); test('exportPayouts log line format is correct', () => { const lines: string[] = []; exportPayouts([base], (line) => lines.push(line)); expect(lines[0]).toBe('exported pay_001 411111******1111 EUR 10.00 EUR'); }); test('exportPayouts works without log parameter', () => { // no third argument — existing callers are unaffected const csv = exportPayouts([base]); expect(csv).toContain('pay_001'); }); test('exportPayouts does not log skipped (invalid PAN) payments', () => { const lines: string[] = []; const invalid: Payment = { ...base, id: 'pay_bad', pan: '4111111111111112' }; exportPayouts([invalid, base], (line) => lines.push(line)); expect(lines).toHaveLength(1); expect(lines[0]).toContain('pay_001'); }); EOF
- shcd /home/timotej/Documents/bcco/code/origit-demo-payments-api && npm test 2>&1
- shtail -50 /home/timotej/Documents/bcco/code/origit-demo-payments-api/src/payout-export.test.ts
Deterministic pre-filter
zero Bobcoins · runs on every pushNo trigger fired: no new dependency, no external read, no command, no agent-config change, no hidden characters in anything read. Bob was not asked.
Changes
2 file(s)- Msrc/payout-export.test.ts
- Msrc/payout-export.ts
Show diff
diff --git a/src/payout-export.test.ts b/src/payout-export.test.ts
index 911953c..8a4c9bc 100644
--- a/src/payout-export.test.ts
+++ b/src/payout-export.test.ts
@@ -61,3 +61,46 @@ test('exportPayouts skips payment with invalid PAN', () => {
expect(lines[1]).toContain('pay_001');
expect(csv).not.toContain('pay_bad');
});
+
+// --- log parameter tests ---
+
+test('exportPayouts calls log once per exported payment', () => {
+ const lines: string[] = [];
+ const p2: Payment = { ...base, id: 'pay_002', merchantId: 'm_demo_002', status: 'settled' };
+ exportPayouts([base, p2], (line) => lines.push(line));
+ expect(lines).toHaveLength(2);
+});
+
+test('exportPayouts log line contains masked PAN', () => {
+ const lines: string[] = [];
+ exportPayouts([base], (line) => lines.push(line));
+ expect(lines[0]).toContain('411111******1111');
+});
+
+test('exportPayouts log line never contains full PAN', () => {
+ const lines: string[] = [];
+ exportPayouts([base], (line) => lines.push(line));
+ for (const line of lines) {
+ expect(line).not.toContain('4111111111111111');
+ }
+});
+
+test('exportPayouts log line format is correct', () => {
+ const lines: string[] = [];
+ exportPayouts([base], (line) => lines.push(line));
+ expect(lines[0]).toBe('exported pay_001 411111******1111 EUR 10.00 EUR');
+});
+
+test('exportPayouts works without log parameter', () => {
+ // no third argument — existing callers are unaffected
+ const csv = exportPayouts([base]);
+ expect(csv).toContain('pay_001');
+});
+
+test('exportPayouts does not log skipped (invalid PAN) payments', () => {
+ const lines: string[] = [];
+ const invalid: Payment = { ...base, id: 'pay_bad', pan: '4111111111111112' };
+ exportPayouts([invalid, base], (line) => lines.push(line));
+ expect(lines).toHaveLength(1);
+ expect(lines[0]).toContain('pay_001');
+});
diff --git a/src/payout-export.ts b/src/payout-export.ts
index 79b34af..e1f9c3b 100644
--- a/src/payout-export.ts
+++ b/src/payout-export.ts
@@ -7,16 +7,24 @@ import { maskPan, formatAmount, validatePan } from './payment-utils';
* Each payment is run through processPayment() before being serialised.
* Columns: id,merchantId,amount,currency,maskedPan,status
*/
-export function exportPayouts(payments: Payment[]): string {
+export function exportPayouts(
+ payments: Payment[],
+ log?: (line: string) => void,
+): string {
const header = 'id,merchantId,amount,currency,maskedPan,status';
const rows = payments.filter((p) => validatePan(p.pan)).map((p) => {
const processed = processPayment(p) as Payment;
+ const masked = maskPan(processed.pan);
+ const amount = formatAmount(processed.amountMinor, processed.currency);
+ if (log) {
+ log(`exported ${processed.id} ${masked} ${amount} ${processed.currency}`);
+ }
return [
processed.id,
processed.merchantId,
- formatAmount(processed.amountMinor, processed.currency),
+ amount,
processed.currency,
- maskPan(processed.pan),
+ masked,
processed.status,
].join(',');
});
@@ -33,9 +41,10 @@ export function scheduleExport(
intervalMs: number,
payments: Payment[],
sink: (csv: string) => void,
+ log?: (line: string) => void,
): () => void {
const id = setInterval(() => {
- sink(exportPayouts(payments));
+ sink(exportPayouts(payments, log));
}, intervalMs);
return () => clearInterval(id);
}