(() => { const listeners = []; const storage = new Map(); const internalSrPreview = new URLSearchParams(location.search).has("internal-sr"); const projectionPreview = new URLSearchParams(location.search).has("projection"); const opportunities = Array.from({ length: 25 }, (_, index) => ({ OptyNumber: `TEST${index + 1}`, OptyId: 1000 + index, Name: `Synthetic opportunity ${index + 1} - Database migration`, CustomerAccount: { PartyUniqueName: "Example public sector customer (Example City, BR)", PartyId: internalSrPreview || projectionPreview ? 789 : "100000810210835", PartyNumber: "test-account", Region_c_localizedValue: "LAD", PrimaryAddress: { CountryCode: "BR" } }, Owner: { PersonFirstName: "Example", PersonLastName: "Owner" }, PrimaryRevenue: { RevnAmountCurcyCode: "USD", RevnAmount: "25000", WinProb: 60 }, EffectiveDate: index === 24 ? null : `2026-11-${String(index < 8 ? 15 : 1 + index).padStart(2, "0")}T00:00:00Z`, LastUpdateDate: "2026-09-15T17:00:00Z", ForecastGroup_c: ["SQL", "PIPELINE", "UPSIDE", "FORECAST", "WON"][index % 5], StatusCode: ["OPEN", "CLOSED", "LOST", "WON", "WON_PENDING"][index % 5] })); const products = [{ ProdGroupName: "Migrate databases to cloud", WorkloadName_c: "Example workload", RevnAmountCurcyCode: "USD", RevnAmount: "25000", TypeCode: "NEWCOMMIT", StatusCode: "OPEN", WinProb: 60, EffectiveDate: "2026-11-15", ConsumptionStartDate_c: "2026-11-15", RampMonths_c: 3 }]; if (projectionPreview) products[0] = { ...products[0], RevnId: 123, RampMonths_c: 2 }; const trend = Array.from({ length: 30 }, (_, index) => ({ fyDate: `2026-09-${String((index % 28) + 1).padStart(2, "0")}`, fiscalTime: [`${String((index % 28) + 1).padStart(2, "0")}-Sep-26`], fiscalQtr: "FY27-Q2", currencyCode: "USD", arrCd: 0, usageCategory: index % 4 ? "Funded Allocation" : "OVERAGE", usedAmount: 1000 + index * 100 })); const authorizations = { accountSummary: { label: "Account-Ti-Authorization", value: "synthetic-accp" }, accountPlans: { label: "G2m-Authorization", value: "synthetic-ocicons" } }; if (projectionPreview) authorizations.workloadActions = { label: "Wwb-Provider-Authorization", value: "synthetic-wwb" }; const runtime = { onMessage: { addListener: listener => listeners.push(listener) }, async sendMessage(message) { const operation = message.type.split(".").at(-1); if (operation === "loadOrganizationChart" || operation === "saveOrganizationChart") { try { return await window.fixtureOrgStorage[operation === "loadOrganizationChart" ? "load" : "save"](message); } catch (error) { return { ok: false, error: error.message }; } } if (operation === "requestWorkloadForecastUpdate") return { ok: true, result: null, debugRequests: [] }; if (operation === "requestWorkloads") return { ok: true, workloads: [{ id: 123, name: "Example workload", adjustedACR: 50000, consumptionStartDate: "2026-11-15T00:00:00", forecast: Array.from({ length: 12 }, (_, index) => ({ month: (5 + index) % 12 + 1, year: index < 7 ? 2026 : 2027, adjustedConsumptionAmount: index < 5 ? 0 : index === 5 ? 1000 : index === 6 ? 3030.30 : 4500 })) }], debugRequests: [] }; if (operation === "requestTimeEntries") return { ok: true, items: [], debugRequests: [] }; if (operation === "requestLookupTaskType") return { ok: true, items: [{ lookUpCode_c: "SCTA_SERVICE_CONFIG", lookUpMeaning_c: "Config", tags_c: "SERVICE" }, { lookUpCode_c: "SCTA_SERVICE_STANDARD", lookUpMeaning_c: "Standard", tags_c: "SERVICE" }, { lookUpCode_c: "SCTA_NON_SERVICE_TRAINING", lookUpMeaning_c: "Training", tags_c: "NON_SERVICE" }], debugRequests: [] }; if (operation === "requestServiceRequestExpand") return { ok: true, items: [...message.srNumbers, "non-service-sr"].map(SrNumber => ({ SrNumber, SRActivities_c: "Account Plan;Customer Research, Assessment and Recommendation;Success Plan" })), debugRequests: [] }; if (operation === "requestResourceUser") return { ok: true, resource: { resourcePartyId: 123 }, debugRequests: [] }; if (operation === "requestActiveServiceRequests") return { ok: true, items: [ { srNumber: "SR0001", srTitle: "Opportunity Pursuit - Example Customer" }, { srNumber: "SR0002", srTitle: "Consumption Services - Example Customer" } ], debugRequests: [] }; if (operation === "requestWeekDetails") { const selected = new Date(`${message.dateReference}T00:00:00Z`); const start = new Date(selected); start.setUTCDate(start.getUTCDate() - (start.getUTCDay() + 1) % 7); const end = new Date(start); end.setUTCDate(end.getUTCDate() + 6); const apiDate = value => `${String(value.getUTCDate()).padStart(2, "0")}-${value.toLocaleDateString("en-US", { month: "short", timeZone: "UTC" }).toUpperCase()}-${value.getUTCFullYear()}`; return { ok: true, items: Array.from({ length: 7 }, (_, index) => { const day = new Date(start); day.setUTCDate(day.getUTCDate() + index); return { Id: index + 1, WeekId: 419, Date: apiDate(day), StartDate: apiDate(start), EndDate: apiDate(end) }; }), debugRequests: [] }; } if (operation === "requestPostInternalServiceRequest") return { ok: true, result: { SrNumber: "ISR123" }, debugRequests: [] }; if (operation === "requestCurrentUser") return { ok: true, user: { id: "example@example.invalid", name: "Example Owner", roles: internalSrPreview ? [] : ["SALES_REP"] }, debugRequests: [] }; if (["prepareSrSession", "requestInternalServiceRequest", "requestWlActions"].includes(operation)) return { ok: true, items: [], actions: [], debugRequests: [] }; if (operation === "requestLookupTypePlatform") return { ok: true, items: [{ code: "OCI", name: "Oracle Cloud Infrastructure" }, { code: "MULTI", name: "Multicloud" }], debugRequests: [] }; if (operation === "requestInternalSrServices") return { ok: true, items: [{ Id: "123", RecordName: "Architecture review", Description_c: "Review the customer architecture, workloads and technical requirements." }, { Id: "124", RecordName: "Technical workshop", Description_c: "Prepare and deliver a technical session for the customer team." }], debugRequests: [] }; if (operation === "getXsrfToken") return { ok: true, token: "synthetic-xsrf", cookieName: "XSRF-TOKEN-TEST" }; if (operation === "requestConsumerTokenService") return { ok: true, authorizations, debugRequests: [] }; if (operation === "requestOpptyProducts") { message.optyNumbers.forEach((optyNumber, index) => listeners.forEach(listener => listener({ type: "opportunitiesExtension.opptyProductsProgress", requestId: message.requestId, optyNumber, items: products, cachedAt: Date.now(), completed: index + 1, total: message.optyNumbers.length, state: index + 1 === message.optyNumbers.length ? "complete" : "running" }))); return { ok: true, requestId: message.requestId }; } if (operation === "requestAccountPlans") return { ok: true, debugRequests: [], plans: ["ACTIVE", "EXPIRED"].map((hdrStatusCode, index) => ({ subPlanNum: `PLAN${index + 1}`, planType: "Universal Credits", hdrStatusCode, bookingCustomer: "Example Customer", soldToPartyName: "Example Sold To", contractId: "synthetic-contract", startDate: "2026-06-01", endDate: "2027-05-31" })) }; if (operation === "requestConsumptionTrend") return { ok: true, items: trend, debugRequests: [] }; throw new Error(`Unexpected synthetic message: ${operation}`); } }; const application = window.createFixtureApplication({ browser: { runtime: { onMessage: runtime.onMessage, sendMessage(message, callback) { const result = runtime.sendMessage(message); if (callback) result.then(callback); return result; } } }, chrome: undefined, localStorage: { getItem: key => storage.get(key) ?? null, setItem: (key, value) => storage.set(key, value) }, async fetch(input, options) { const url = new URL(input); let body; if (url.pathname === "/fscmRestApi/tokenrelay") body = { access_token: "synthetic-fusion-token", expires_in: 3600 }; else if (url.pathname.endsWith("/opportunities")) { if (window.fixtureOpportunitiesDelay) await new Promise(resolve => setTimeout(resolve, window.fixtureOpportunitiesDelay)); (window.fixtureOpportunitiesByContact ||= []).push(url.toString()); const offset = Number(url.searchParams.get("offset")); body = { items: Array.from({length: offset ? 1 : 5}, (_, i) => ({ OptyNumber: "CONTACT" + (offset + i), Name: "Contact opportunity " + (offset + i), WinProb: 60, CurrencyCode: "BRL", Revenue: "5656658", EffectiveDate: "2024-05-08", StatusCode: "CLOSED" })), totalResults: 6, hasMore: offset === 0 }; } else if (url.pathname.endsWith("custom-actions/queries")) { if (options.method === "GET") return Response.json({ items: [{ isDefault: true, savedSearchNumber: "fixture-default" }] }); const { offset, limit, entity, keywords } = JSON.parse(options.body); if (entity === "Contact") { (window.fixtureContactQueries ||= []).push(keywords); if (window.fixtureContactsFailure) return new Response("Synthetic contacts failure", { status: 503 }); const contacts = ["Alex Morgan", "Taylor Chen", "Jordan Silva", "Sam Rivera"].map((PartyName, index) => ({ PartyName, PartyId: String(2000 + index), PartyNumber: String(18000 + index), JobTitle: ["Chief Technology Officer", "Infrastructure Director", "Data and Analytics Director", "Cloud Architect"][index], PrimaryEmail: { EmailAddress: "contact" + index + "@example.invalid" }, PrimaryAccount: { PartyName: "Example Customer" } })); if (window.fixtureContactDelay?.[keywords]) await new Promise(resolve => setTimeout(resolve, window.fixtureContactDelay[keywords])); (window.fixtureContactCompleted ||= []).push(keywords); return Response.json({ items: contacts.filter(contact => contact.PartyId === keywords || contact.PartyName.toLowerCase().includes(keywords.toLowerCase())).map(contact => ({ ...contact, ...window.fixtureContactOverrides?.[contact.PartyId] })), hasMore: false }); } if (entity === "CRMServiceRequest") return new Response(JSON.stringify({ items: [{ SrId: "123456", SrNumber: "SR123456", Title: "Example parent SR", PrimaryPillarNew_c: "Tech_Cloud_Infrastructure", CustomerDeadline_c: "2026-11-30T00:00:00.000+0000", ReportedHours_c: 4, OpportunityName_Id_c: { OptyNumber: "TEST1" } }], hasMore: false }), { status: 200 }); body = { items: opportunities.slice(offset, offset + limit), totalResults: opportunities.length, count: Math.min(limit, opportunities.length - offset), hasMore: offset + limit < opportunities.length, offset, limit }; } else if (url.pathname.endsWith("summarizations/generate")) body = { summaryText: "Synthetic AI summary.\nText is displayed safely: ." }; else throw new Error(`Unexpected synthetic fetch: ${url.pathname}`); return new Response(JSON.stringify(body), { status: 200, headers: { "Content-Type": "application/json" } }); } }); application.productsContentJobs.ensureProductsBackgroundMessageHandler(); document.getElementById("open").addEventListener("click", () => application.contentModal.openOpportunitiesModal()); application.contentModal.openOpportunitiesModal(); })();