feat(orchestrator): export and import the accounts as CSV or TSV
Requirement 065. GET /api/accounts/export?format=csv|tsv answers the accounts as an attachment, one header line and one line per account, with spreadsheet formulas guarded. POST /api/accounts/import/preview parses an uploaded file (base64, size and row limits, UTF-8 with an optional byte order mark), detects or takes the separator, maps the columns by header or by the operator's mapping and marks each row new, update, unchanged or error. POST /api/accounts/import/apply writes the previewed rows in one Ledger.batch, keep or overwrite per conflicting email, and refuses when the ledger digest changed since the preview. The Accounts page gains export links, the file picker, the mapping sheet and the per-conflict choice. 🎯 Fix: 88 % 💥 Break: 5 % 💸 Tokens: 100 % ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 84 🚦 Gate: ⛔ fix 88 % < 90 (E2E spec not run yet): operator approved the commit Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30862411f3
commit
5c969be21c
6 files changed
+809
-6
No files matched your search
@@ -10,6 +10,13 @@ from .diffs import SEALED_SUFFIX
|
||||
from .records import read_json, stamp, write_atomic
|
||||
|
||||
|
||||
def unused(items: dict[str, dict]) -> str:
|
||||
item_id = secrets.token_hex(8)
|
||||
while item_id in items:
|
||||
item_id = secrets.token_hex(8)
|
||||
return item_id
|
||||
|
||||
|
||||
class Ledger:
|
||||
def __init__(self, file: Path) -> None:
|
||||
self.file = file
|
||||
@@ -20,10 +27,24 @@ class Ledger:
|
||||
|
||||
def fresh(self) -> str:
|
||||
with self.changed:
|
||||
item_id = secrets.token_hex(8)
|
||||
while item_id in self.items:
|
||||
item_id = secrets.token_hex(8)
|
||||
return item_id
|
||||
return unused(self.items)
|
||||
|
||||
def batch(self, check: Callable[[list[dict]], None], changes: dict[str, dict], added: list[dict]) -> None:
|
||||
"""Args:
|
||||
check: raises to refuse the whole batch; it sees every record
|
||||
under the lock the write holds.
|
||||
changes: fields merged into the record of each id, which keeps
|
||||
its id and created stamp.
|
||||
added: new records, each under a fresh id.
|
||||
"""
|
||||
with self.changed:
|
||||
check(self.listed())
|
||||
items = {**self.items, **{item_id: {**self.items[item_id], **fields} for item_id, fields in changes.items()}}
|
||||
created = stamp()
|
||||
for fields in added:
|
||||
item_id = unused(items)
|
||||
items[item_id] = {**fields, "id": item_id, "created": created}
|
||||
self.write(items)
|
||||
|
||||
def write(self, items: dict[str, dict]) -> None:
|
||||
write_atomic(self.file, json.dumps(items, indent=1, sort_keys=True).encode("utf-8"))
|
||||
|
||||
Reference in new issue
Block a user