आर्किटेक्चर
मूल डाउनलोड करें ↓CRM-142 आर्किटेक्चर
मौजूदा सीमाएँ (अपरिवर्तित)
src/contacts.js initialContacts, normalEmail(value), validContact(row), addContact(rows, row), searchContacts(rows, query='') एक्सपोर्ट करता है। अंतिम संपर्क ID और trimming के लिए normalization/validation तथा addContact दोबारा इस्तेमाल करें। src/storage.js readContacts() और async saveContacts(rows, {fail=false}={}) एक्सपोर्ट करता है; यह केवल इसे बदलता है: agentbay-crm-142-contacts 180ms की देरी के बाद। दोनों मॉड्यूल अपरिवर्तित रखें। src/app.js सूची रेंडर करना, खोज और Add contact एकीकरण रखता है।
शुद्ध आयात मॉड्यूल
बनाएँ src/import.js जिसमें ठीक वही सार्वजनिक एक्सपोर्ट हों जो इसमें ज़रूरी हैं: docs/import-contract.md:
previewCSV(text, existing)→{rows, counts: {ready, invalid, duplicate}}। हर पंक्ति:{record, name, email, company, status, reason}; record गैर-खाली डेटा रिकॉर्ड की 1 से शुरू संख्या है, status यह है:ready|invalid|duplicate, Ready के लिए reason खाली है। DOM/स्टोरेज की पहुँच या स्थायी भंडारण नहीं।mergeReady(preview, existing)→{contacts, added, skipped}। नया array लौटाएँ, सभी मौजूदा objects/data सुरक्षित रखें, दोनों में से किसी इनपुट को कभी न बदलें। दिए गए वर्तमान संपर्क और पहले स्वीकार पंक्तियों से Ready पंक्ति के फ़ील्ड व सामान्यीकृत ईमेल फिर जाँचें; नए ID के लिए addContact इस्तेमाल करें। skipped, preview.rows.length में से added घटाने के बराबर है, नए टकराने वाले Ready रिकॉर्ड सहित।
field-start, unquoted, quoted और after-quote स्थितियों वाला कैरेक्टर स्कैनर इस्तेमाल करें; दोहरे उद्धरण सँभालें; delimiter और record separator को केवल उद्धरण के बाहर पहचानें। preview से पहले भटके उद्धरण, बंद उद्धरण के बाद टेक्स्ट, खुले उद्धरण और बहुत अधिक फ़ील्ड अस्वीकार करें। शुरुआती BOM हटाएँ; LF/CRLF, उद्धरण वाले कॉमा और नई पंक्तियाँ सँभालें। trim/lowercase से हेडर सामान्यीकृत करें, डुप्लिकेट और अनुपस्थित name/email अस्वीकार करें। छोटी पंक्तियाँ भरें, अज्ञात अलग हेडर के फ़ील्ड अनदेखे करें। पार्स किए केवल whitespace रिकॉर्ड छोड़ें। TextEncoder UTF-8 byteLength <=100000 और गैर-खाली डेटा रिकॉर्ड <=500 लागू करें। ईमेल आरक्षित करने से पहले फ़ील्ड जाँचें: अमान्य पंक्तियाँ बाद की वैध पंक्तियाँ डुप्लिकेट न बनाएँ। मौजूदा संपर्कों से सामान्यीकृत ईमेल सेट शुरू करें; फ़ाइल की पहली वैध प्रविष्टि मान्य हो।
UI स्थिति और लिखने का क्रम
इसमें src/app.js, यह बनाए रखें: rows कमिट किए संपर्कों के रूप में। पैनल की phase जोड़ें (closed|select|reading|review|saving), चुनी हुई File, preview, रीड generation token, एक synchronous global writeBusy flag और failNextSave boolean। renderImport() टेक्स्ट नोड/कार्ड, गिनती और disabled स्थितियाँ बनाता है। चयन/रद्द पर generation बढ़ाएँ; देर से आए file.text() परिणाम छोड़ें। पढ़ने से पहले File.size जाँचें और previewCSV में बाइट फिर लागू करें।
सभी Add और Import राइट एक ऐप-स्वामित्व वाले persistContacts(makeNext) async coordinator से हों: किसी await से पहले synchronously writeBusy लें; दूसरी कोशिश अस्वीकार करें, Add/Import के बदलाव नियंत्रण बंद करें, फिर सबसे नए committed rows से makeNext बुलाएँ। Import factory mergeReady(preview, rows) बुलाती है; Add factory addContact(rows, input) को {contacts, added:{0} skipped:0} में रखती है, जो coordinator के परिणाम का स्वरूप है। इससे इस पेज पर राइट क्रम में होते हैं; यह cross-tab lock नहीं है। failNextSave केवल saveContacts(next, {fail}) बुलाते समय लें; पूरा होने के बाद ही next को rows में प्रकाशित और render करें। अस्वीकार होने पर committed rows, input/preview और retry नियंत्रण रखें; finally में busy छोड़ें। स्टोरेज key कभी साफ़/हटाएँ नहीं। सफल आयात preview बंद करता है, ताकि कतारबद्ध/डबल क्लिक दोबारा इस्तेमाल न करें। फिर सत्यापन पर कोई addition न हो तो अनावश्यक save के बिना सही zero-added/all-skipped सार के साथ सूची पर लौटें।
पूर्वावलोकन अस्थायी है। फिर सत्यापन में save से ठीक पहले पेज की सबसे नई सफल rows इस्तेमाल हों, अपलोड के समय का स्नैपशॉट नहीं। यह केवल ब्राउज़र का अभ्यास है; multi-tab transaction, remote database concurrency या delivery verification नहीं देता। localStorage origin/browser-profile के हिसाब से अलग है, विफल हो सकता है और ब्राउज़र डेटा साफ़ करने पर आयात किए संपर्क मिटते हैं। नेटवर्क अपलोड या नई स्टोरेज key नहीं।
रेंडरिंग और विफलता की सीमा
CSV सामग्री, filenames, कारण और सार के लिए createElement/textContent/replaceChildren इस्तेमाल करें, मौजूदा सुरक्षित सूची renderer की तरह। innerHTML interpolation इस्तेमाल न करें। मौजूदा #status लाइव क्षेत्र को बनाए रखें। संरचना/रीड की त्रुटियाँ केवल आयात योग्य preview हटाएँ, committed संपर्क कभी नहीं। save विफल हो तो preview रहे; स्थायी रूप से सहेजना सफल हुआ या नहीं, केवल adapter तय करे। UI और focus नियम यहाँ हैं: docs/screen-design.md.
मूल फ़ाइल और स्रोत का विवरण
output/docs/architecture.md.txt · SHA-256 69d6f9009c7611dac555bd970d0b58d9346461bb735a225f6b2aa7d80887b557
# CRM-142 architecture
## Existing boundaries (unchanged)
`src/contacts.js` exports initialContacts, normalEmail(value), validContact(row), addContact(rows, row), searchContacts(rows, query=''). Reuse normalization/validation and addContact for final contact IDs and trimming. `src/storage.js` exports readContacts() and async saveContacts(rows, {fail=false}={}); it replaces only `agentbay-crm-142-contacts` after a 180ms delay. Leave both modules unchanged. `src/app.js` retains list rendering, search and Add contact integration.
## Pure import module
Create `src/import.js` with exactly the public exports required by `docs/import-contract.md`:
- `previewCSV(text, existing)` → `{rows, counts: {ready, invalid, duplicate}}`. Each row: `{record, name, email, company, status, reason}`; record is the 1-based nonblank data-record number, status is `ready|invalid|duplicate`, reason is empty for Ready. No DOM/storage access or persistence.
- `mergeReady(preview, existing)` → `{contacts, added, skipped}`. Return a new array, preserve all existing objects/data, never mutate either input. Revalidate Ready row fields and normalized emails against the passed current contacts and earlier accepted rows; use addContact for new IDs. skipped equals preview.rows.length minus added, including newly conflicting Ready records.
Use a character scanner with field-start, unquoted, quoted and after-quote states; handle doubled quotes, delimiters and record separators only outside quotes. Reject stray quotes, text after a closing quote, unclosed quotes and too many fields before producing a preview. Strip initial BOM; support LF/CRLF, quoted commas and embedded newlines. Normalize header names by trim/lowercase, reject duplicates and missing name/email. Pad shorter rows, ignore distinct unknown header fields. Ignore parsed all-whitespace records. Enforce TextEncoder UTF-8 byteLength <=100000 and <=500 nonblank data records. Validate fields before reserving emails: invalid rows cannot make later valid rows duplicate. Seed normalized email set from existing contacts; first valid file occurrence wins.
## UI state and write ordering
In `src/app.js`, retain `rows` as committed contacts. Add panel phase (`closed|select|reading|review|saving`), selected File, preview, read generation token, a synchronous global writeBusy flag and failNextSave boolean. `renderImport()` creates text nodes/cards, counts and disabled states. Increment generation on selection/cancel; ignore late file.text() results. Check File.size before reading and enforce bytes again in previewCSV.
All Add and Import writes use one app-owned `persistContacts(makeNext)` async coordinator: synchronously acquire writeBusy before any await; reject a second attempt, disable Add/Import mutation controls, then call makeNext with latest committed rows. Import's factory calls mergeReady(preview, rows); Add's factory wraps addContact(rows, input) as {contacts, added:1, skipped:0}, matching the coordinator result shape. This serializes writes in this page; it is not a cross-tab lock. Consume failNextSave only when calling saveContacts(next, {fail}); publish next to rows and render only after resolution. On rejection preserve committed rows, input/preview and retry controls; release busy in finally. Never clear/remove the storage key. Successful import closes preview, so queued/double clicks cannot reuse it. Zero additions after revalidation return to list with accurate zero-added/all-skipped summary without an unnecessary save.
Preview is transient. Revalidation uses latest successful in-page rows immediately before save, not a captured upload snapshot. This browser-only exercise provides no multi-tab transaction, remote database concurrency or delivery verification. localStorage is origin/browser-profile specific, may fail, and clearing browser data removes imported contacts. No network upload or new storage key.
## Rendering and failure boundary
Use createElement/textContent/replaceChildren for CSV content, filenames, reasons and summaries, matching the existing safe list renderer. Do not use innerHTML interpolation. Keep existing `#status` live region. Structural/read errors discard importable preview only, never committed contacts. Save failure retains preview and only the adapter decides persistence success. UI details and focus rules are in `docs/screen-design.md`.