diff --git a/Dockerfile b/Dockerfile index 3cc84f7..52d2104 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN rm -rf /usr/share/nginx/html/* COPY nginx.conf /etc/nginx/conf.d/default.conf # Publish web assets only. Backend source, tests and local configuration are not static downloads. -COPY index.html app.js style.css sw.js manifest.json gt_full_catalog.json /usr/share/nginx/html/ +COPY index.html app.js workspace.js style.css sw.js manifest.json gt_full_catalog.json /usr/share/nginx/html/ COPY assets/ /usr/share/nginx/html/assets/ COPY data/ /usr/share/nginx/html/data/ diff --git a/Dockerfile.api b/Dockerfile.api index 3f143f1..16bf3e1 100644 --- a/Dockerfile.api +++ b/Dockerfile.api @@ -5,7 +5,7 @@ ENV NODE_ENV=production PORT=3000 STUDIO_DATA_DIR=/data/studio COPY package.json package-lock.json ./ RUN npm ci --omit=dev --ignore-scripts --no-fund --no-audit COPY server/ ./server/ -COPY index.html app.js style.css sw.js manifest.json gt_full_catalog.json ./public/ +COPY index.html app.js workspace.js style.css sw.js manifest.json gt_full_catalog.json ./public/ COPY assets/ ./public/assets/ COPY data/ ./public/data/ RUN mkdir -p /data/studio && chown -R node:node /app /data/studio diff --git a/app.js b/app.js index ee50c95..f69a753 100644 --- a/app.js +++ b/app.js @@ -19,10 +19,10 @@ const I18N_DICTIONARY = { poster_mode_label: "ডিসপ্লে মোড (Display Mode):", mode_single_btn: "🎯 ১টি প্রোডাক্ট হিরো ৩ডি স্টেজ", mode_multi_btn: "🔲 মাল্টি-প্রোডাক্ট গ্রিড ভিউ (৩-৪টি প্রোডাক্ট)", - trends_label: "🔥 গুগল ট্রেন্ডিং সার্চ (Google Trends 1-Click Load):", - trends_badge: "Realtime BD Trends", + trends_label: "🛍️ আপনার catalog থেকে বাছুন:", + trends_badge: "Workspace catalog", product_input_label: "প্রডাক্ট লিংক বা নাম (Product Link or Name):", - open_catalog_btn: "🛍️ GT ক্যাটালগ লিস্ট (560+)", + open_catalog_btn: "🛍️ আপনার catalog", product_input_ph: "e.g. Silk Saree, Smartwatch, Pure Honey, Sneaker or Skincare", product_price_label: "মূল্য ও অফার (Price & Discount):", product_price_ph: "e.g. ৳ ১,০৬০ (৳ ১,৪৭০) 28% OFF", @@ -220,10 +220,10 @@ const I18N_DICTIONARY = { poster_mode_label: "Display Mode:", mode_single_btn: "🎯 1 Product Hero 3D Stage", mode_multi_btn: "🔲 Multi-Product Grid View (3-4 Products)", - trends_label: "🔥 Google Trending Searches (Google Trends 1-Click Load):", - trends_badge: "Realtime BD Trends", + trends_label: "🛍️ Choose from your catalog:", + trends_badge: "Workspace catalog", product_input_label: "Product Link or Name:", - open_catalog_btn: "🛍️ GT Catalog List (560+)", + open_catalog_btn: "🛍️ Your catalog", product_input_ph: "e.g. Silk Saree, Smartwatch, Pure Honey, Sneaker or Skincare", product_price_label: "Price & Discount Offer:", product_price_ph: "e.g. ৳ 1,060 (৳ 1,470) 28% OFF", @@ -465,7 +465,17 @@ window.applyLanguage = function(lang) { if (typeof renderHistory === 'function') renderHistory(); }; -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener('aura-studio-ready', () => { + const brandSelect = document.getElementById('brandWatermarkSelect'); + if (brandSelect) brandSelect.replaceChildren(new Option(window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant, 'workspace')); + const storeContext = document.getElementById('inboxStoreContext'); + if (storeContext) storeContext.value = window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant; + ['productInput', 'productPrice', 'customBadgeInput', 'ugcProductName', 'ugcTargetAudience', 'gridMainHeadlineInput'].forEach(id => { + const field = document.getElementById(id); if (field) field.value = ''; + }); + for (let slot = 1; slot <= 4; slot++) { + ['slotTitle', 'slotPrice', 'slotBadge'].forEach(prefix => { const field = document.getElementById(prefix + slot); if (field) field.value = ''; }); + } initNavigation(); initSettings(); initCatalogBrowser(); @@ -552,9 +562,9 @@ function initSettings() { const statusMsg = document.getElementById('settingsStatusMsg'); // Load saved settings - const savedKey = localStorage.getItem('opal_gemini_api_key') || ''; - const savedModel = localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash'; - const savedN8n = localStorage.getItem('opal_n8n_webhook') || 'https://n8n.auraajenticai.cloud/webhook/gt-auto-post'; + const savedKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || ''; + const savedModel = window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash'; + const savedN8n = window.AuraStudio.local.getItem('opal_n8n_webhook') || ''; if (apiKeyInput) apiKeyInput.value = savedKey; if (modelSelect) modelSelect.value = savedModel; @@ -567,11 +577,11 @@ function initSettings() { const n8nUrl = n8nWebhookInput ? n8nWebhookInput.value.trim() : ''; if (n8nUrl) { - localStorage.setItem('opal_n8n_webhook', n8nUrl); + window.AuraStudio.local.setItem('opal_n8n_webhook', n8nUrl); } if (!key) { - localStorage.setItem('opal_selected_model', model); + window.AuraStudio.local.setItem('opal_selected_model', model); statusMsg.classList.remove('hidden'); statusMsg.style.color = '#10B981'; statusMsg.textContent = '✅ Settings saved (Offline templates active).'; @@ -585,8 +595,8 @@ function initSettings() { try { const res = await callGeminiApi(key, model, "Respond with: 'Aura Studio Connected successfully!'"); if (res) { - localStorage.setItem('opal_gemini_api_key', key); - localStorage.setItem('opal_selected_model', model); + window.AuraStudio.local.setItem('opal_gemini_api_key', key); + window.AuraStudio.local.setItem('opal_selected_model', model); statusMsg.style.color = '#10B981'; statusMsg.textContent = `✅ Verified & Active: ${res.trim()}`; } @@ -606,7 +616,7 @@ function getCachedPromptResult(cacheKey) { return GEMINI_CACHE.get(cacheKey); } try { - const stored = sessionStorage.getItem(`opal_cache_${cacheKey}`); + const stored = window.AuraStudio.session.getItem(`opal_cache_${cacheKey}`); if (stored) { const parsed = JSON.parse(stored); if (Date.now() - parsed.ts < 1000 * 60 * 60 * 2) { // 2 hour cache @@ -621,7 +631,7 @@ function getCachedPromptResult(cacheKey) { function setCachedPromptResult(cacheKey, data) { GEMINI_CACHE.set(cacheKey, data); try { - sessionStorage.setItem(`opal_cache_${cacheKey}`, JSON.stringify({ ts: Date.now(), data })); + window.AuraStudio.session.setItem(`opal_cache_${cacheKey}`, JSON.stringify({ ts: Date.now(), data })); } catch (e) {} } @@ -638,7 +648,7 @@ async function callGeminiApi(apiKey, model, prompt, retries = 2) { } const modelHierarchy = [ - model || localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash', + model || window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash', 'gemini-1.5-flash', 'gemma-2-27b-it' ]; @@ -1012,7 +1022,7 @@ function initMiniAppsHub() { } function getCustomMiniApps() { - return JSON.parse(localStorage.getItem('opal_custom_apps') || '[]'); + return JSON.parse(window.AuraStudio.local.getItem('opal_custom_apps') || '[]'); } function renderMiniApps() { @@ -1105,7 +1115,7 @@ function initMiniAppBuilder() { const existing = getCustomMiniApps(); existing.unshift(newApp); - localStorage.setItem('opal_custom_apps', JSON.stringify(existing)); + window.AuraStudio.local.setItem('opal_custom_apps', JSON.stringify(existing)); statusMsg.classList.remove('hidden'); statusMsg.style.color = '#10B981'; @@ -1193,7 +1203,7 @@ window.closeAppRunner = function() { }; // Handle Mini-App Execution -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener('aura-studio-ready', () => { const execBtn = document.getElementById('runnerExecuteBtn'); if (execBtn) { execBtn.addEventListener('click', async () => { @@ -1212,7 +1222,7 @@ document.addEventListener('DOMContentLoaded', () => { const inputs = document.querySelectorAll('.runner-input'); const selectedBrandKey = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch'; const activeBrand = getBrandProfile(selectedBrandKey); - const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, ''); + const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, ''); const dynamicWaLink = `https://wa.me/88${cleanPhone}`; let prompt = currentRunningApp.promptTemplate || 'Generate helpful response for the user.'; @@ -1231,8 +1241,8 @@ document.addEventListener('DOMContentLoaded', () => { prompt = prompt.replace(/{{wa_link}}/g, dynamicWaLink); prompt = prompt.replace(/https:\/\/wa\.me\/8801712426871/g, dynamicWaLink); - const apiKey = localStorage.getItem('opal_gemini_api_key') || ''; - const model = currentRunningApp.model || localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash'; + const apiKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || ''; + const model = currentRunningApp.model || window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash'; try { let output = ''; @@ -1705,9 +1715,9 @@ function initPosterLab() { shareWhatsAppBtn.addEventListener('click', () => { const selectedBrand = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch'; const activeBrand = getBrandProfile(selectedBrand); - const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, ''); + const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, ''); const pTitle = productInput.value.trim() || 'Authentic Product'; - const text = encodeURIComponent(`✨ Hello! I want to order: ${pTitle}\nWebsite: https://${activeBrand.footerSite || 'glamourstouch.com'}\nHotline: ${activeBrand.footerHotline}`); + const text = encodeURIComponent(`✨ Hello! I want to order: ${pTitle}\nWebsite: https://${activeBrand.footerSite || ''}\nHotline: ${activeBrand.footerHotline}`); window.open(`https://wa.me/88${cleanPhone}?text=${text}`, '_blank'); }); @@ -1717,7 +1727,7 @@ function initPosterLab() { if (autoPostN8nBtn) { autoPostN8nBtn.addEventListener('click', async () => { - const webhookUrl = localStorage.getItem('opal_n8n_webhook'); + const webhookUrl = window.AuraStudio.local.getItem('opal_n8n_webhook'); if (!webhookUrl) { alert('⚠️ Please configure n8n Webhook URL in Settings first!'); switchToTab('tabSettings'); @@ -1732,7 +1742,7 @@ function initPosterLab() { try { const selectedBrand = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch'; const activeBrand = getBrandProfile(selectedBrand); - const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, ''); + const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, ''); const pTitle = productInput.value.trim() || 'Authentic Product'; const pPrice = productPrice.value.trim() || '৳ ১,০৬০'; const posterDataUrl = posterCanvas.toDataURL('image/jpeg', 0.92); @@ -1774,100 +1784,17 @@ function initPosterLab() { // --- Dynamic Brand Profiles & Tenant Sync Engine --- const DEFAULT_BRAND_PROFILES = { - glamourstouch: { - id: 'glamourstouch', - headerTitle: "✨ GLAMOUR'S TOUCH ✨", - headerSub: '100% AUTHENTIC KOREAN COSMETICS • DERMATOLOGIST TESTED', - badgeL1: '🌿 Pure & Safe Care', - badgeL2: '🛡️ Authentic Seal', - footerSite: 'glamourstouch.com', - footerHotline: '01712-426871', - theme: 'obsidian_gold', - category: 'cosmetics' - }, - panjabi: { - id: 'panjabi', - headerTitle: '👑 AURA HERITAGE PANJABI 👑', - headerSub: 'ROYAL DESIGNER PANJABI & KABLI SUITS • 100% PURE COTTON & SILK', - badgeL1: '🧵 100% Pre-Shrunk Weave', - badgeL2: '✨ Size Trial Available', - footerSite: 'panjabi.auraajenticai.cloud', - footerHotline: '01712-426871', - theme: 'obsidian_gold', - category: 'panjabi' - }, - snehalata: { - id: 'snehalata', - headerTitle: '🌸 SNEHALATA AURA 🌸', - headerSub: 'PREMIUM LUXURY FASHION, SAREE & LIFESTYLE • 100% AUTHENTIC', - badgeL1: '👗 Pure Fabric Weave', - badgeL2: '✨ Size Trial Guarantee', - footerSite: 'snehalata.com', - footerHotline: '01712-426871', - theme: 'rose_quartz', - category: 'fashion' - }, - techvolt: { - id: 'techvolt', - headerTitle: '⚡ TECHVOLT GADGETS ⚡', - headerSub: 'OFFICIAL WARRANTY • SMART ELECTRONICS & AUDIO ACCESSORIES', - badgeL1: '🔋 High Battery Life', - badgeL2: '🛡️ 1 Year Warranty', - footerSite: 'techvolt.auraajenticai.cloud', - footerHotline: '01712-426871', - theme: 'cyber_neon', - category: 'electronics' - }, - organic: { - id: 'organic', - headerTitle: '🍯 PRANON ORGANIC 🍯', - headerSub: '100% PURE NATURAL HONEY & UNADULTERATED ORGANIC FOODS', - badgeL1: '🌿 100% Lab Tested', - badgeL2: '🛡️ Double Money Back', - footerSite: 'organic.auraajenticai.cloud', - footerHotline: '01712-426871', - theme: 'botanical_eco', - category: 'organic' - }, - sneakerlab: { - id: 'sneakerlab', - headerTitle: '👟 SNEAKERLAB BD 👟', - headerSub: 'PREMIUM STREETWEAR & GENUINE LEATHER FOOTWEAR', - badgeL1: '👟 Memory Foam Cushion', - badgeL2: '✨ Doorstep Fitting', - footerSite: 'sneakers.auraajenticai.cloud', - footerHotline: '01712-426871', - theme: 'obsidian_gold', - category: 'sneakerlab' - }, - royale: { - id: 'royale', - headerTitle: '💎 AURA ROYALE 💎', - headerSub: 'LUXURY JEWELRY, WATCHES & 24-HOUR SIGNATURE PERFUMES', - badgeL1: '💎 24h Projection', - badgeL2: '👑 Pure Luxury Finish', - footerSite: 'royale.auraajenticai.cloud', - footerHotline: '01712-426871', - theme: 'obsidian_gold', - category: 'royale' - }, - custom: { - id: 'custom', - headerTitle: '🛍️ UNIVERSAL MERCHANT 🛍️', - headerSub: '100% ORIGINAL AUTHENTIC • CASH ON DELIVERY BANGLADESH', - badgeL1: '⭐ Premium Quality', - badgeL2: '🛡️ 100% Original', - footerSite: 'auraajenticai.cloud', - footerHotline: '01712-426871', - theme: 'obsidian_gold', - category: 'general' + workspace: { + id: 'workspace', headerTitle: window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant, + headerSub: '', badgeL1: '', badgeL2: '', footerSite: '', footerHotline: '', + theme: 'obsidian_gold', category: 'general' } }; function getDynamicBrandProfiles() { let customMap = {}; try { - const saved = localStorage.getItem('opal_custom_brands'); + const saved = window.AuraStudio.local.getItem('opal_custom_brands'); if (saved) customMap = JSON.parse(saved); } catch (e) {} return Object.assign({}, DEFAULT_BRAND_PROFILES, customMap); @@ -1875,7 +1802,7 @@ function getDynamicBrandProfiles() { function getBrandProfile(brandKey) { const all = getDynamicBrandProfiles(); - return all[brandKey] || all.glamourstouch; + return all[brandKey] || all.workspace; } // Universal Dynamic Product Resolver @@ -6206,7 +6133,8 @@ window.loadCgiIntoPosterLab = function(promptId) { } }; -async function drawWhatsAppQrOnCanvas(ctx, x, y, size, hotline = '01712-426871') { +async function drawWhatsAppQrOnCanvas(ctx, x, y, size, hotline = '') { + if (!String(hotline).replace(/\D/g, '')) return; ctx.fillStyle = '#FFFFFF'; roundRect(ctx, x - 4, y - 4, size + 8, size + 8, 10); ctx.fill(); @@ -6266,12 +6194,12 @@ function initInboxAI() { generateBtn.addEventListener('click', async () => { const query = customerMsgInput.value.trim(); const storeInfo = storeContextInput.value.trim(); - const apiKey = localStorage.getItem('opal_gemini_api_key') || ''; - const model = localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash'; + const apiKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || ''; + const model = window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash'; const selectedBrand = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch'; const activeBrand = getBrandProfile(selectedBrand); - const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, ''); + const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, ''); const dynamicWaLink = `https://wa.me/88${cleanPhone}`; if (!query) { @@ -6331,7 +6259,7 @@ function initHistory() { function renderHistory() { if (!historyContainer) return; const dict = I18N_DICTIONARY[window.currentLang] || I18N_DICTIONARY.bn; - const list = JSON.parse(localStorage.getItem('opal_history') || '[]'); + const list = JSON.parse(window.AuraStudio.local.getItem('opal_history') || '[]'); if (list.length === 0) { historyContainer.innerHTML = `