Hello from MCP server
// import fs from "fs/promises";
// import path from "path";
import { check, getApi, getPb, wait, waitMs } from "./common.js";
import { tnfrTiers } from "./tnfrLegacyBook.js";
import { legacyPlumbingCosts } from "./legacyPlumbingCosts.js";
import plumbingOffers from "./tnfrLegacy/plumbingOffers.json" with { type: "json" };
import plumbingTitles from "./tnfrLegacy/plumbingTitles.json" with { type: "json" };
import plumbingMenus from "./tnfrLegacy/plumbingMenus.json" with { type: "json" };
import plumbingMenuCopy from "./tnfrLegacy/menuCopy.json" with { type: "json" };
import { getProblems } from "./legacyPlumbingProblems.js";
import { allTags } from "./tnfrLegacy/problemTags.js";
import { allProblemsWithDescriptions } from "./tnfrLegacy/problemDescriptions.js";
import { warrantyCopyItems, warrantyContentItems } from "./tnfrLegacyBook.js";
const users = {
rodney: {
name: "Rodney Koop",
email: "rodney@thenewflatrate.com",
password: "averysecretphrase",
org: "The New Flat Rate",
orgId: "",
tiersBook: "",
variables: {
hourlyFee: 9.857708577,
serviceCallFee: 2.602435064,
saDiscount: 1,
salesTax: 1.1,
},
},
};
export async function tnfrLegacy(api) {
await check(async () => {
await api.register(users.rodney);
const r = await api.createOrg(users.rodney, users.rodney.variables);
users.rodney.orgId = r.id;
}, "Rodney can register and create an org");
await check(async () => {
const tiersBook = await api.createBook(
users.rodney,
users.rodney.orgId,
"TNFR Legacy Tiers",
"tnfrLegacyTiers",
null,
null,
);
const plumbingCostsBook = await api.createBook(
users.rodney,
users.rodney.orgId,
"TNFR Legacy Plumbing Costs",
"tnfrLegacyPlumbingCosts",
null,
null,
);
const plumbingBookChanges = await api.createBook(
users.rodney,
users.rodney.orgId,
"TNFR Legacy Plumbing Book",
"tnfrLegacyPlumbing",
null,
[tiersBook.id, plumbingCostsBook.id],
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
tiersBook.id,
warrantyContentItems,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
tiersBook.id,
warrantyCopyItems,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
tiersBook.id,
tnfrTiers,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingCostsBook.id,
legacyPlumbingCosts,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
plumbingTitles,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
plumbingMenuCopy,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
plumbingOffers,
);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
plumbingMenus,
);
const menus = (await api.listMenus(users.rodney)).map((i) => i.refId);
const plumbingProblems = getProblems(menus);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
plumbingProblems,
);
// Create ALL problem tags first (including the original "drain" tag)
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
allTags,
);
// Add descriptions and comprehensive tags to ALL problems (filtering out non-existent menus)
// Filter out problems that reference non-existent menus
const excludedProblems = [
"PF15_problem",
"PG12_problem",
"PH15_problem",
"PH18_problem",
"PO1_problem",
"PO5_problem",
];
const validProblems = allProblemsWithDescriptions.filter(
(problem) => !excludedProblems.includes(problem.data?.refId),
);
// Process in batches of 25 to avoid API limits
const batchSize = 25;
for (let i = 0; i < validProblems.length; i += batchSize) {
const batch = validProblems.slice(i, i + batchSize);
await api.publishChanges(
users.rodney,
users.rodney.orgId,
plumbingBookChanges.id,
batch,
);
// Small delay between batches to prevent overwhelming the API
await waitMs(100);
}
}, "Rodney can create books");
}