382 lines
16 KiB
JavaScript
382 lines
16 KiB
JavaScript
import { PrismaClient } from "@prisma/client";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { randomBytes, scryptSync } from "node:crypto";
|
|
|
|
function loadEnvFromDotEnv() {
|
|
const p = path.resolve(process.cwd(), ".env");
|
|
if (!fs.existsSync(p)) return;
|
|
const raw = fs.readFileSync(p, "utf8");
|
|
for (const line of raw.split("\n")) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const idx = trimmed.indexOf("=");
|
|
if (idx === -1) continue;
|
|
const key = trimmed.slice(0, idx).trim();
|
|
let val = trimmed.slice(idx + 1).trim();
|
|
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
val = val.slice(1, -1);
|
|
}
|
|
if (!key) continue;
|
|
if (key === "DATABASE_URL") {
|
|
process.env[key] = val;
|
|
continue;
|
|
}
|
|
if (!process.env[key]) process.env[key] = val;
|
|
}
|
|
}
|
|
|
|
loadEnvFromDotEnv();
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
const LOGIN_PHONE = "+15550000001";
|
|
const LOGIN_PASSWORD = "ConnectFlow#2026";
|
|
const LOGIN_NAME = "Connect Owner";
|
|
|
|
const SCRYPT_KEY_LENGTH = 64;
|
|
|
|
function hashPassword(password) {
|
|
const salt = randomBytes(16).toString("base64url");
|
|
const digest = scryptSync(password, salt, SCRYPT_KEY_LENGTH).toString("base64url");
|
|
return `scrypt$${salt}$${digest}`;
|
|
}
|
|
|
|
function atOffset(days, hour, minute) {
|
|
const d = new Date();
|
|
d.setDate(d.getDate() + days);
|
|
d.setHours(hour, minute, 0, 0);
|
|
return d;
|
|
}
|
|
|
|
function plusMinutes(date, minutes) {
|
|
const d = new Date(date);
|
|
d.setMinutes(d.getMinutes() + minutes);
|
|
return d;
|
|
}
|
|
|
|
function buildOdooAiContacts(teamId) {
|
|
const prospects = [
|
|
{ name: "Olivia Reed", company: "RetailNova", country: "USA", location: "New York", email: "olivia.reed@retailnova.com", phone: "+1 555 120 0101" },
|
|
{ name: "Daniel Kim", company: "ForgePeak Manufacturing", country: "USA", location: "Chicago", email: "daniel.kim@forgepeak.com", phone: "+1 555 120 0102" },
|
|
{ name: "Marta Alonso", company: "Iberia Foods Group", country: "Spain", location: "Barcelona", email: "marta.alonso@iberiafoods.es", phone: "+34 91 555 0103" },
|
|
{ name: "Youssef Haddad", company: "GulfTrade Distribution", country: "UAE", location: "Dubai", email: "youssef.haddad@gulftrade.ae", phone: "+971 4 555 0104" },
|
|
{ name: "Emma Collins", company: "NorthBridge Logistics", country: "UK", location: "London", email: "emma.collins@northbridge.co.uk", phone: "+44 20 5550 0105" },
|
|
{ name: "Noah Fischer", company: "Bergmann Auto Parts", country: "Germany", location: "Munich", email: "noah.fischer@bergmann-auto.de", phone: "+49 89 5550 0106" },
|
|
{ name: "Ava Choi", company: "Pacific MedTech Supply", country: "Singapore", location: "Singapore", email: "ava.choi@pacificmedtech.sg", phone: "+65 6555 0107" },
|
|
{ name: "Liam Dubois", company: "HexaCommerce", country: "France", location: "Paris", email: "liam.dubois@hexacommerce.fr", phone: "+33 1 55 50 0108" },
|
|
{ name: "Maya Shah", company: "Zenith Consumer Brands", country: "Canada", location: "Toronto", email: "maya.shah@zenithbrands.ca", phone: "+1 416 555 0109" },
|
|
{ name: "Arman Petrosyan", company: "Ararat Electronics", country: "Armenia", location: "Yerevan", email: "arman.petrosyan@ararat-electronics.am", phone: "+374 10 555110" },
|
|
{ name: "Sophia Martinez", company: "Sunline Home Goods", country: "USA", location: "Austin", email: "sophia.martinez@sunlinehg.com", phone: "+1 555 120 0111" },
|
|
{ name: "Leo Novak", company: "CentralBuild Materials", country: "Germany", location: "Berlin", email: "leo.novak@centralbuild.de", phone: "+49 30 5550 0112" },
|
|
{ name: "Isla Grant", company: "BlueHarbor Pharma", country: "UK", location: "Manchester", email: "isla.grant@blueharbor.co.uk", phone: "+44 161 555 0113" },
|
|
{ name: "Mateo Rossi", company: "Milano Fashion House", country: "Italy", location: "Milan", email: "mateo.rossi@milanofh.it", phone: "+39 02 5550 0114" },
|
|
{ name: "Nina Volkova", company: "Polar AgriTech", country: "Kazakhstan", location: "Almaty", email: "nina.volkova@polaragri.kz", phone: "+7 727 555 0115" },
|
|
{ name: "Ethan Park", company: "Vertex Components", country: "South Korea", location: "Seoul", email: "ethan.park@vertexcomponents.kr", phone: "+82 2 555 0116" },
|
|
{ name: "Zara Khan", company: "Crescent Retail Chain", country: "UAE", location: "Abu Dhabi", email: "zara.khan@crescentretail.ae", phone: "+971 2 555 0117" },
|
|
{ name: "Hugo Silva", company: "Luso Industrial Systems", country: "Portugal", location: "Lisbon", email: "hugo.silva@lusois.pt", phone: "+351 21 555 0118" },
|
|
{ name: "Chloe Bernard", company: "Santex Clinics Network", country: "France", location: "Lyon", email: "chloe.bernard@santex.fr", phone: "+33 4 55 50 0119" },
|
|
{ name: "James Walker", company: "Metro Wholesale Group", country: "USA", location: "Los Angeles", email: "james.walker@metrowholesale.com", phone: "+1 555 120 0120" },
|
|
];
|
|
|
|
return prospects.map((p, idx) => {
|
|
const female = idx % 2 === 0;
|
|
const picIdx = (idx % 70) + 1;
|
|
return {
|
|
teamId,
|
|
name: p.name,
|
|
company: p.company,
|
|
country: p.country,
|
|
location: p.location,
|
|
avatarUrl: `https://randomuser.me/api/portraits/${female ? "women" : "men"}/${picIdx}.jpg`,
|
|
email: p.email,
|
|
phone: p.phone,
|
|
};
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
const passwordHash = hashPassword(LOGIN_PASSWORD);
|
|
|
|
const user = await prisma.user.upsert({
|
|
where: { id: "demo-user" },
|
|
update: { phone: LOGIN_PHONE, passwordHash, name: LOGIN_NAME, email: "owner@clientsflow.local" },
|
|
create: {
|
|
id: "demo-user",
|
|
phone: LOGIN_PHONE,
|
|
passwordHash,
|
|
name: LOGIN_NAME,
|
|
email: "owner@clientsflow.local",
|
|
},
|
|
});
|
|
|
|
const team = await prisma.team.upsert({
|
|
where: { id: "demo-team" },
|
|
update: { name: "Connect Workspace" },
|
|
create: { id: "demo-team", name: "Connect Workspace" },
|
|
});
|
|
|
|
await prisma.teamMember.upsert({
|
|
where: { teamId_userId: { teamId: team.id, userId: user.id } },
|
|
update: { role: "OWNER" },
|
|
create: { teamId: team.id, userId: user.id, role: "OWNER" },
|
|
});
|
|
|
|
const conversation = await prisma.chatConversation.upsert({
|
|
where: { id: `pilot-${team.id}` },
|
|
update: { title: "Pilot" },
|
|
create: { id: `pilot-${team.id}`, teamId: team.id, createdByUserId: user.id, title: "Pilot" },
|
|
});
|
|
|
|
await prisma.$transaction([
|
|
prisma.feedCard.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.contactPin.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.workspaceDocument.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.deal.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.calendarEvent.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.contactMessage.deleteMany({ where: { contact: { teamId: team.id } } }),
|
|
prisma.chatMessage.deleteMany({ where: { teamId: team.id, conversationId: conversation.id } }),
|
|
prisma.omniMessage.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.omniThread.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.omniContactIdentity.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.telegramBusinessConnection.deleteMany({ where: { teamId: team.id } }),
|
|
prisma.contact.deleteMany({ where: { teamId: team.id } }),
|
|
]);
|
|
|
|
const contacts = await prisma.contact.createManyAndReturn({
|
|
data: buildOdooAiContacts(team.id),
|
|
select: { id: true, name: true, company: true },
|
|
});
|
|
|
|
const integrationModules = [
|
|
"Sales + CRM + forecasting copilot",
|
|
"Inventory + demand prediction",
|
|
"Purchase + supplier risk scoring",
|
|
"Accounting + AI anomaly detection",
|
|
"Helpdesk + ticket triage assistant",
|
|
"Manufacturing + production planning AI",
|
|
];
|
|
|
|
await prisma.contactNote.createMany({
|
|
data: contacts.map((c, idx) => ({
|
|
contactId: c.id,
|
|
content:
|
|
`${c.company ?? c.name} is evaluating Odoo implementation with AI extensions. ` +
|
|
`Primary integration scope: ${integrationModules[idx % integrationModules.length]}. ` +
|
|
`Main buying trigger: reduce manual operations and shorten decision cycles. ` +
|
|
`Next milestone: run discovery workshop, confirm data owners, and approve pilot KPI pack.`,
|
|
})),
|
|
});
|
|
|
|
const channels = ["TELEGRAM", "WHATSAPP", "INSTAGRAM", "EMAIL"];
|
|
const contactMessages = [];
|
|
for (let i = 0; i < contacts.length; i += 1) {
|
|
const contact = contacts[i];
|
|
const base = atOffset(-(i % 18), 9 + (i % 7), (i * 7) % 60);
|
|
|
|
contactMessages.push({
|
|
contactId: contact.id,
|
|
kind: "MESSAGE",
|
|
direction: "IN",
|
|
channel: channels[i % channels.length],
|
|
content: `Hi, we are reviewing Odoo + AI rollout for ${contact.company}. Can we align on integration timeline this week?`,
|
|
occurredAt: base,
|
|
});
|
|
|
|
contactMessages.push({
|
|
contactId: contact.id,
|
|
kind: "MESSAGE",
|
|
direction: "OUT",
|
|
channel: channels[(i + 1) % channels.length],
|
|
content: "Sure. I suggest a 45-min discovery focused on workflows, API constraints, and pilot KPIs.",
|
|
occurredAt: plusMinutes(base, 22),
|
|
});
|
|
|
|
contactMessages.push({
|
|
contactId: contact.id,
|
|
kind: "MESSAGE",
|
|
direction: i % 3 === 0 ? "OUT" : "IN",
|
|
channel: channels[(i + 2) % channels.length],
|
|
content: "Status update: technical scope is clear; blocker is budget owner approval and security questionnaire.",
|
|
occurredAt: plusMinutes(base, 65),
|
|
});
|
|
|
|
if (i % 3 === 0) {
|
|
contactMessages.push({
|
|
contactId: contact.id,
|
|
kind: "CALL",
|
|
direction: "OUT",
|
|
channel: "PHONE",
|
|
content: "Discovery call: Odoo modules, data flows, AI use-cases",
|
|
durationSec: 180 + ((i * 23) % 420),
|
|
transcriptJson: [
|
|
`${contact.name}: We need phased rollout, starting from Sales and Inventory.`,
|
|
"You: Agreed. We can run a 6-week pilot with KPI baseline and weekly checkpoints.",
|
|
],
|
|
occurredAt: plusMinutes(base, 110),
|
|
});
|
|
}
|
|
}
|
|
await prisma.contactMessage.createMany({ data: contactMessages });
|
|
|
|
await prisma.calendarEvent.createMany({
|
|
data: contacts.flatMap((c, idx) => {
|
|
const firstStart = atOffset((idx % 21) - 3, 10 + (idx % 6), (idx * 5) % 60);
|
|
const secondStart = atOffset((idx % 28) + 1, 14 + (idx % 4), (idx * 3) % 60);
|
|
return [
|
|
{
|
|
teamId: team.id,
|
|
contactId: c.id,
|
|
title: `Discovery: Odoo + AI with ${c.company ?? c.name}`,
|
|
startsAt: firstStart,
|
|
endsAt: plusMinutes(firstStart, 30),
|
|
note: "Confirm integration scope, current stack, and pilot success metrics.",
|
|
status: "planned",
|
|
},
|
|
{
|
|
teamId: team.id,
|
|
contactId: c.id,
|
|
title: `Architecture workshop: ${c.company ?? c.name}`,
|
|
startsAt: secondStart,
|
|
endsAt: plusMinutes(secondStart, 45),
|
|
note: "Review API mapping, ETL boundaries, and AI assistant guardrails.",
|
|
status: idx % 6 === 0 ? "done" : "planned",
|
|
},
|
|
];
|
|
}),
|
|
});
|
|
|
|
const stages = ["Lead", "Discovery", "Solution Fit", "Proposal", "Negotiation", "Pilot", "Contract Review"];
|
|
await prisma.deal.createMany({
|
|
data: contacts.map((c, idx) => ({
|
|
teamId: team.id,
|
|
contactId: c.id,
|
|
title: `${c.company ?? "Account"} Odoo + AI integration`,
|
|
stage: stages[idx % stages.length],
|
|
amount: 18000 + (idx % 8) * 7000,
|
|
nextStep:
|
|
idx % 4 === 0
|
|
? "Send pilot proposal and finalize integration backlog."
|
|
: "Run solution workshop and align commercial owner on timeline.",
|
|
summary:
|
|
"Potential deal for phased Odoo implementation with AI copilots for ops, sales, and planning. " +
|
|
"Commercial model: discovery + pilot + rollout.",
|
|
})),
|
|
});
|
|
|
|
await prisma.contactPin.createMany({
|
|
data: contacts.map((c, idx) => ({
|
|
teamId: team.id,
|
|
contactId: c.id,
|
|
text:
|
|
idx % 3 === 0
|
|
? "Pinned: ask for ERP owner, data owner, and target go-live quarter."
|
|
: "Pinned: keep communication around one KPI and one next action.",
|
|
})),
|
|
});
|
|
|
|
const proposalKeys = ["create_followup", "open_comm", "call", "draft_message", "run_summary", "prepare_question"];
|
|
await prisma.feedCard.createMany({
|
|
data: contacts
|
|
.filter((_, idx) => idx % 3 === 0)
|
|
.slice(0, 80)
|
|
.map((c, idx) => ({
|
|
teamId: team.id,
|
|
contactId: c.id,
|
|
happenedAt: atOffset(-(idx % 6), 9 + (idx % 8), (idx * 9) % 60),
|
|
text:
|
|
`I reviewed ${c.company ?? c.name} account activity for the Odoo + AI opportunity. ` +
|
|
"There is enough momentum to move the deal one stage with a concrete next action.",
|
|
proposalJson: {
|
|
title: idx % 2 === 0 ? "Schedule pilot scoping call" : "Send unblock note for budget owner",
|
|
details: [
|
|
`Contact: ${c.name}`,
|
|
idx % 2 === 0 ? "Timing: this week, 45 minutes" : "Timing: today in primary channel",
|
|
"Goal: confirm scope, owner, and next commercial checkpoint",
|
|
],
|
|
key: proposalKeys[idx % proposalKeys.length],
|
|
},
|
|
})),
|
|
});
|
|
|
|
await prisma.workspaceDocument.createMany({
|
|
data: [
|
|
{
|
|
teamId: team.id,
|
|
title: "Odoo integration discovery checklist",
|
|
type: "Regulation",
|
|
owner: "Solution Team",
|
|
scope: "Pre-sale discovery",
|
|
summary: "Mandatory questions before estimation of Odoo + AI rollout.",
|
|
body: "## Must capture\n- Current ERP modules\n- Integration endpoints\n- Data owner per domain\n- Security constraints\n- Pilot KPI baseline",
|
|
updatedAt: atOffset(-1, 11, 10),
|
|
},
|
|
{
|
|
teamId: team.id,
|
|
title: "AI copilot playbook for Odoo",
|
|
type: "Playbook",
|
|
owner: "AI Practice Lead",
|
|
scope: "Use-case qualification",
|
|
summary: "How to position forecasting, assistant, and anomaly detection features.",
|
|
body: "## Flow\n1. Process pain\n2. Data quality\n3. Model target\n4. Success KPI\n5. Pilot scope",
|
|
updatedAt: atOffset(-2, 15, 0),
|
|
},
|
|
{
|
|
teamId: team.id,
|
|
title: "Pilot pricing matrix",
|
|
type: "Policy",
|
|
owner: "Commercial Ops",
|
|
scope: "Discovery and pilot contracts",
|
|
summary: "Price ranges for discovery, pilot, and production rollout phases.",
|
|
body: "## Typical ranges\n- Discovery: 5k-12k\n- Pilot: 15k-45k\n- Rollout: 50k+\n\nAlways tie cost to scope and timeline.",
|
|
updatedAt: atOffset(-3, 9, 30),
|
|
},
|
|
{
|
|
teamId: team.id,
|
|
title: "Security and compliance template",
|
|
type: "Template",
|
|
owner: "Delivery Office",
|
|
scope: "Enterprise prospects",
|
|
summary: "Template answers for data residency, RBAC, audit trail, and PII handling.",
|
|
body: "## Sections\n- Hosting model\n- Access control\n- Logging and audit\n- Data retention\n- Incident response",
|
|
updatedAt: atOffset(-4, 13, 45),
|
|
},
|
|
{
|
|
teamId: team.id,
|
|
title: "Integration architecture blueprint",
|
|
type: "Playbook",
|
|
owner: "Architecture Team",
|
|
scope: "Technical workshops",
|
|
summary: "Reference architecture for Odoo connectors, ETL, and AI service layer.",
|
|
body: "## Layers\n- Odoo core modules\n- Integration bus\n- Data warehouse\n- AI service endpoints\n- Monitoring",
|
|
updatedAt: atOffset(-5, 10, 0),
|
|
},
|
|
{
|
|
teamId: team.id,
|
|
title: "Go-live readiness checklist",
|
|
type: "Regulation",
|
|
owner: "PMO",
|
|
scope: "Pilot to production transition",
|
|
summary: "Checklist to move from pilot acceptance to production launch.",
|
|
body: "## Required\n- Pilot KPIs approved\n- Rollout backlog prioritized\n- Owners assigned\n- Support model defined",
|
|
updatedAt: atOffset(-6, 16, 15),
|
|
},
|
|
],
|
|
});
|
|
|
|
console.log("Seed completed.");
|
|
console.log(`Login phone: ${LOGIN_PHONE}`);
|
|
console.log(`Login password: ${LOGIN_PASSWORD}`);
|
|
console.log(`Team: ${team.name}`);
|
|
console.log(`Contacts created: ${contacts.length}`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exitCode = 1;
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|