diff --git a/src/geo-brand-presence-daily/geo-brand-presence-refresh-handler.js b/src/geo-brand-presence-daily/geo-brand-presence-refresh-handler.js new file mode 100644 index 000000000..982ed16ee --- /dev/null +++ b/src/geo-brand-presence-daily/geo-brand-presence-refresh-handler.js @@ -0,0 +1,31 @@ +/* c8 ignore start */ +/* + * Copyright 2025 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +/* eslint-disable header/header */ + +import { refreshGeoBrandPresenceSheetsHandler } from '../geo-brand-presence/geo-brand-presence-refresh-handler.js'; + +/** + * Daily version of the geo brand presence refresh handler + * Sends refresh:geo-brand-presence-daily messages to Mystique + */ +export async function refreshGeoBrandPresenceSheetsHandlerDaily(message, context) { + // Inject daily cadence into context + const dailyContext = { + ...context, + brandPresenceCadence: 'daily', + }; + + // Call the base handler with the enhanced context + return refreshGeoBrandPresenceSheetsHandler(message, dailyContext); +} diff --git a/src/geo-brand-presence/detect-geo-brand-presence-handler.js b/src/geo-brand-presence/detect-geo-brand-presence-handler.js index e3f9f423a..13a9d5a54 100644 --- a/src/geo-brand-presence/detect-geo-brand-presence-handler.js +++ b/src/geo-brand-presence/detect-geo-brand-presence-handler.js @@ -45,7 +45,7 @@ export default async function handler(message, context) { log.debug('GEO BRAND PRESENCE: Message received:', message); - if (!subType || ![...OPPTY_TYPES, 'refresh:geo-brand-presence'].includes(subType)) { + if (!subType || ![...OPPTY_TYPES, 'refresh:geo-brand-presence', 'refresh:geo-brand-presence-daily'].includes(subType)) { log.error(`GEO BRAND PRESENCE: Unsupported subtype: ${subType}`); return notFound(); } @@ -69,7 +69,7 @@ export default async function handler(message, context) { : `${site.getConfig().getLlmoDataFolder()}/brand-presence`; const outputLocations = [mainOutputLocation, `${mainOutputLocation}/config_${configVersion || 'absent'}`]; - if (subType === 'refresh:geo-brand-presence') { + if (subType === 'refresh:geo-brand-presence' || subType === 'refresh:geo-brand-presence-daily') { return handleRefresh({ auditId, outputLocations, presignedURL }, context); } diff --git a/src/geo-brand-presence/geo-brand-presence-refresh-handler.js b/src/geo-brand-presence/geo-brand-presence-refresh-handler.js index 04309de2c..b5cc4f93a 100644 --- a/src/geo-brand-presence/geo-brand-presence-refresh-handler.js +++ b/src/geo-brand-presence/geo-brand-presence-refresh-handler.js @@ -120,6 +120,14 @@ export async function refreshGeoBrandPresenceSheetsHandler(message, context) { let errMsg; const site = await Site.findById(siteId); + // Priority: context (for wrapper) > site config > default + const brandPresenceCadence = context.brandPresenceCadence + || site.getConfig()?.getBrandPresenceCadence?.() + || 'weekly'; + const isDaily = brandPresenceCadence === 'daily'; + + log.info('%s: Processing refresh with cadence: %s for site %s', AUDIT_NAME, brandPresenceCadence, siteId); + // fetch sheets that need to be refreshed from SharePoint // Get the SharePoint client const sharepointClient = await createLLMOSharepointClient(context); @@ -208,8 +216,13 @@ export async function refreshGeoBrandPresenceSheetsHandler(message, context) { { expiresIn: 86_400 /* seconds, 24h */ }, ); + // Determine message type based on cadence + const messageType = isDaily + ? 'refresh:geo-brand-presence-daily' + : 'refresh:geo-brand-presence'; + const msg = createMystiqueMessage({ - type: 'refresh:geo-brand-presence', + type: messageType, auditId, baseURL, siteId, @@ -222,7 +235,8 @@ export async function refreshGeoBrandPresenceSheetsHandler(message, context) { }); await sqs.sendMessage(env.QUEUE_SPACECAT_TO_MYSTIQUE, msg); - log.info('%s: Sent sheet %s to Mystique for processing', AUDIT_NAME, sheetName, msg); + const cadenceLabel = isDaily ? ' DAILY' : ''; + log.info('%s%s: Sent sheet %s to Mystique for processing', AUDIT_NAME, cadenceLabel, sheetName, msg); return true; })); @@ -292,4 +306,4 @@ function errorMsg(error) { return error instanceof Error ? error.message : String(error); } -const RE_SHEET_NAME = /^brandpresence-(?.+?)-w(?\d{2})-(?\d{4})$/; +const RE_SHEET_NAME = /^brandpresence-(?.+?)-w(?\d{2})-(?\d{4})(?:-\d+)?$/; diff --git a/src/index.js b/src/index.js index 5f82724d0..155e66224 100644 --- a/src/index.js +++ b/src/index.js @@ -125,6 +125,7 @@ const HANDLERS = { 'geo-brand-presence-daily': geoBrandPresenceDaily, 'geo-brand-presence-trigger-refresh': refreshGeoBrandPresenceSheetsHandler, 'detect:geo-brand-presence-daily': detectGeoBrandPresenceDaily, + 'refresh:geo-brand-presence-daily': detectGeoBrandPresenceDaily, 'guidance:forms-a11y': formAccessibilityGuidance, 'detect:forms-a11y': mystiqueDetectedFormAccessibilityOpportunity, 'guidance:accessibility-remediation': accessibilityRemediationGuidance, diff --git a/src/llmo-customer-analysis/handler.js b/src/llmo-customer-analysis/handler.js index 052407281..485601b8f 100644 --- a/src/llmo-customer-analysis/handler.js +++ b/src/llmo-customer-analysis/handler.js @@ -326,7 +326,7 @@ export async function runLlmoCustomerAnalysis(finalUrl, context, site, auditCont await triggerGeoBrandPresence(context, site, auditContext); triggeredSteps.push(brandPresenceCadence === 'daily' ? 'geo-brand-presence-daily' : 'geo-brand-presence'); } - if (brandPresenceCadence !== 'daily' && needsBrandPresenceRefresh) { + if (needsBrandPresenceRefresh) { log.info('LLMO config changes detected in brand or competitor aliases; triggering geo-brand-presence-refresh'); await triggerGeoBrandPresenceRefresh(context, site, configVersion); triggeredSteps.push('geo-brand-presence-refresh');