fix: resolve all JS architecture violations (JS-005 through JS-009)

Fixed 89 violations across vendor, admin, and shared JavaScript files:

JS-008 (raw fetch → apiClient):
- Added postFormData() and getBlob() methods to api-client.js
- Updated inventory.js, messages.js to use apiClient.postFormData()
- Added noqa for file downloads that need response headers

JS-009 (window.showToast → Utils.showToast):
- Updated admin/messages.js, notifications.js, vendor/messages.js
- Replaced alert() in customers.js

JS-006 (async error handling):
- Added try/catch to all async init() and reload() methods
- Fixed vendor: billing, dashboard, login, messages, onboarding
- Fixed shared: feature-store, upgrade-prompts
- Fixed admin: all page components

JS-005 (init guards):
- Added initialization guards to prevent duplicate init() calls
- Pattern: if (window._componentInitialized) return;

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-31 21:32:19 +01:00
parent c8fd09d16f
commit 265c71f597
48 changed files with 410 additions and 196 deletions

View File

@@ -61,20 +61,28 @@ function vendorMessages(initialConversationId = null) {
* Initialize component
*/
async init() {
messagesLog.debug('Initializing vendor messages page');
await Promise.all([
this.loadConversations(),
this.loadRecipients()
]);
// Guard against multiple initialization
if (window._vendorMessagesInitialized) return;
window._vendorMessagesInitialized = true;
if (this.selectedConversationId) {
await this.loadConversation(this.selectedConversationId);
try {
messagesLog.debug('Initializing vendor messages page');
await Promise.all([
this.loadConversations(),
this.loadRecipients()
]);
if (this.selectedConversationId) {
await this.loadConversation(this.selectedConversationId);
}
// Start polling for new messages
this.startPolling();
} catch (error) {
messagesLog.error('Failed to initialize messages page:', error);
} finally {
this.loading = false;
}
this.loading = false;
// Start polling for new messages
this.startPolling();
},
/**
@@ -128,7 +136,7 @@ function vendorMessages(initialConversationId = null) {
messagesLog.debug(`Loaded ${this.conversations.length} conversations`);
} catch (error) {
messagesLog.error('Failed to load conversations:', error);
window.showToast?.('Failed to load conversations', 'error');
Utils.showToast('Failed to load conversations', 'error');
} finally {
this.loadingConversations = false;
}
@@ -177,7 +185,7 @@ function vendorMessages(initialConversationId = null) {
this.scrollToBottom();
} catch (error) {
messagesLog.error('Failed to load conversation:', error);
window.showToast?.('Failed to load conversation', 'error');
Utils.showToast('Failed to load conversation', 'error');
} finally {
this.loadingMessages = false;
}
@@ -231,20 +239,7 @@ function vendorMessages(initialConversationId = null) {
const formData = new FormData();
formData.append('content', this.replyContent);
const response = await fetch(`/api/v1/vendor/messages/${this.selectedConversationId}/messages`, {
method: 'POST',
body: formData,
headers: {
'Authorization': `Bearer ${window.getAuthToken?.() || ''}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.detail || 'Failed to send message');
}
const message = await response.json();
const message = await apiClient.postFormData(`/vendor/messages/${this.selectedConversationId}/messages`, formData);
// Add to messages
if (this.selectedConversation) {
@@ -260,7 +255,7 @@ function vendorMessages(initialConversationId = null) {
this.scrollToBottom();
} catch (error) {
messagesLog.error('Failed to send message:', error);
window.showToast?.(error.message || 'Failed to send message', 'error');
Utils.showToast(error.message || 'Failed to send message', 'error');
} finally {
this.sendingMessage = false;
}
@@ -286,10 +281,10 @@ function vendorMessages(initialConversationId = null) {
const conv = this.conversations.find(c => c.id === this.selectedConversationId);
if (conv) conv.is_closed = true;
window.showToast?.('Conversation closed', 'success');
Utils.showToast('Conversation closed', 'success');
} catch (error) {
messagesLog.error('Failed to close conversation:', error);
window.showToast?.('Failed to close conversation', 'error');
Utils.showToast('Failed to close conversation', 'error');
}
},
@@ -307,10 +302,10 @@ function vendorMessages(initialConversationId = null) {
const conv = this.conversations.find(c => c.id === this.selectedConversationId);
if (conv) conv.is_closed = false;
window.showToast?.('Conversation reopened', 'success');
Utils.showToast('Conversation reopened', 'success');
} catch (error) {
messagesLog.error('Failed to reopen conversation:', error);
window.showToast?.('Failed to reopen conversation', 'error');
Utils.showToast('Failed to reopen conversation', 'error');
}
},
@@ -354,10 +349,10 @@ function vendorMessages(initialConversationId = null) {
await this.loadConversations();
await this.selectConversation(response.id);
window.showToast?.('Conversation created', 'success');
Utils.showToast('Conversation created', 'success');
} catch (error) {
messagesLog.error('Failed to create conversation:', error);
window.showToast?.(error.message || 'Failed to create conversation', 'error');
Utils.showToast(error.message || 'Failed to create conversation', 'error');
} finally {
this.creatingConversation = false;
}