Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/geo-brand-presence-daily/geo-brand-presence-refresh-handler.js
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 2 additions & 2 deletions src/geo-brand-presence/detect-geo-brand-presence-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}

Expand Down
20 changes: 17 additions & 3 deletions src/geo-brand-presence/geo-brand-presence-refresh-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?.()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still does not exist, does it?
will it ever exist?
otherwise delete it :)

|| '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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}));

Expand Down Expand Up @@ -292,4 +306,4 @@ function errorMsg(error) {
return error instanceof Error ? error.message : String(error);
}

const RE_SHEET_NAME = /^brandpresence-(?<webSearchProvider>.+?)-w(?<week>\d{2})-(?<year>\d{4})$/;
const RE_SHEET_NAME = /^brandpresence-(?<webSearchProvider>.+?)-w(?<week>\d{2})-(?<year>\d{4})(?:-\d+)?$/;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/llmo-customer-analysis/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down