facebook / modules /mockData.js
Althnayi's picture
Upload 27 files
2a196ac verified
Raw
History Blame Contribute Delete
8.4 kB
// ============================================================================
// FRITREE ENTERPRISE PLATFORM - DEVELOPMENT TESTING & MOCK DATA UTILITY
// File: modules/mockData.js (Complete & Hardened Implementation)
// ============================================================================
(function(global) {
'use strict';
/**
* Generates a randomized date within the last 7 days
*/
function getRandomDateInLastWeek() {
const now = new Date();
const pastDays = Math.floor(Math.random() * 7);
const hours = Math.floor(Math.random() * 24);
const minutes = Math.floor(Math.random() * 60);
now.setDate(now.getDate() - pastDays);
now.setHours(hours, minutes, 0, 0);
return now.toISOString();
}
/**
* Populates mock categories, assets, and campaign history logs into local storage.
* Use this to instantly populate the Analytics graphs, Dashboard metrics, and
* Campaign History table.
*/
async function injectMockWorkspaceData() {
try {
console.log("[Fritree Mock Utility] Preparing data payload injection...");
// 1. Generate Mock Categories
const mockCategories = [
{ id: "cat_realestate", name: "Real Estate Promotions", color: "#1877f2", parentId: null },
{ id: "cat_ecom", name: "E-Commerce Deals", color: "#10b981", parentId: null },
{ id: "cat_tech", name: "Software & Technology", color: "#8b5cf6", parentId: null },
{ id: "cat_clearance", name: "Seasonal Clearance", color: "#f59e0b", parentId: null }
];
// 2. Generate Mock Content Library Assets
const mockAssets = [
{
uuid: "cl_asset_001",
title: "Modern Apartment Showcase",
textMain: "Stunning 2-bedroom luxury apartments available now in the downtown district! {High ceilings|Floor-to-ceiling windows} with premium finishes and {amazing views|spacious balconies}. Contact us today to schedule an exclusive tour! #RealEstate #LuxuryLiving",
textSec: "Luxury downtown living awaits you. Schedule a viewing today!",
status: "Active",
categories: ["cat_realestate"],
keywords: ["apartments", "luxury", "rent"],
priority: 80,
expireDate: "",
cooldownMinutes: 15,
notes: "High conversion rate on urban development groups",
media: [],
creationDate: getRandomDateInLastWeek(),
modifiedDate: new Date().toISOString(),
stats: { usage: 12, success: 10, fail: 1, pending: 1, realInteractions: 45 },
scores: { quality: 85, performance: 83 },
lastPublished: getRandomDateInLastWeek()
},
{
uuid: "cl_asset_002",
title: "Flash Sale 50% Off Promo",
textMain: "⚡ FLASH SALE! Get 50% off on all items across our store for the next {24 hours|12 hours} only! Use code {FLASH50|HALFPRICE} at checkout. {Don't miss out!|Order now before stocks run out!}",
textSec: "50% off sitewide. Limited time only!",
status: "Active",
categories: ["cat_ecom", "cat_clearance"],
keywords: ["sale", "promo", "discount"],
priority: 95,
expireDate: "",
cooldownMinutes: 30,
notes: "High-priority flash promotion",
media: [],
creationDate: getRandomDateInLastWeek(),
modifiedDate: new Date().toISOString(),
stats: { usage: 24, success: 20, fail: 2, pending: 2, realInteractions: 112 },
scores: { quality: 90, performance: 83 },
lastPublished: getRandomDateInLastWeek()
},
{
uuid: "cl_asset_003",
title: "SaaS Automation Platform launch",
textMain: "Scale up your workflow with our advanced {no-code automation engine|all-in-one productivity suite}. Free 14-day trial, {no credit card required|instant setup}. Discover why thousands of businesses trust us.",
textSec: "Automate your daily operational workflows easily.",
status: "Active",
categories: ["cat_tech"],
keywords: ["saas", "software", "productivity"],
priority: 60,
expireDate: "",
cooldownMinutes: 10,
notes: "Excellent for professional B2B communities",
media: [],
creationDate: getRandomDateInLastWeek(),
modifiedDate: new Date().toISOString(),
stats: { usage: 8, success: 6, fail: 1, pending: 1, realInteractions: 14 },
scores: { quality: 75, performance: 75 },
lastPublished: getRandomDateInLastWeek()
}
];
// 3. Generate Historical Campaign Reports
const mockHistory = [];
const platforms = ['facebook', 'whatsapp'];
for (let i = 1; i <= 15; i++) {
const platform = platforms[Math.floor(Math.random() * platforms.length)];
const isFb = platform === 'facebook';
const total = Math.floor(Math.random() * 25) + 5;
const success = Math.round(total * (0.7 + Math.random() * 0.3));
const failed = total - success;
const campaignDate = new Date();
campaignDate.setDate(campaignDate.getDate() - Math.floor(Math.random() * 7));
const logs = [];
for (let j = 0; j < total; j++) {
logs.push({
groupId: isFb ? `1234567890${j}` : `+1555000000${j}`,
status: j < success ? 'success' : 'failed',
error: j < success ? null : 'Group post submission restricted',
postUrl: j < success ? `https://www.facebook.com/groups/posts/${Date.now() + j}/` : null
});
}
const mockHistoryRecord = {
id: 'hist_mock_' + i + '_' + Date.now(),
name: isFb ? `Historical Campaign Wave #${i}` : 'Bulk Product Announcement',
date: campaignDate.toISOString(),
platform: platform,
type: Math.random() > 0.5 ? 'Manual' : 'Scheduled',
status: 'Completed',
isLibraryMode: Math.random() > 0.5,
config: { text: "Sample marketing campaign test payload.", images: [] },
stats: { total: total, success: success, pending: 0, failed: failed },
logs: logs
};
mockHistory.unshift(mockHistoryRecord);
}
// Save elements securely using FritreeStorage (which handles encryption)
await FritreeStorage.set('local_content_library', mockAssets);
await FritreeStorage.set('local_content_categories', mockCategories);
await FritreeStorage.set('campaignHistoryData', mockHistory);
if (typeof window.addLog === 'function') {
window.addLog("Content Library and campaign history successfully seeded with metrics data.", "success");
}
alert("Diagnostics Workspace Environment Mock Data Generated successfully! Reloading to sync widgets...");
window.location.reload();
} catch (e) {
console.error("Failed to generate and commit mock data.", e);
}
}
// Exported Helper APIs
global.FritreeDeveloperTools = {
seedMockData: injectMockWorkspaceData
};
})(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);