From 9f3607e4725a6750668312ad9d99b140d0869406 Mon Sep 17 00:00:00 2001 From: ekremney Date: Thu, 29 Aug 2024 16:41:22 +0200 Subject: [PATCH 1/5] feat: high bounce rate and low ctr opportunities --- package-lock.json | 6 +++--- package.json | 2 +- src/opportunities/opportunities.js | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9f59f6c4..0b28f5dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "2.8.0", + "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?9b54c84d774a490e107c56c51db8d7a38562c8c9", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@adobe/spacecat-shared-utils": "1.19.6", "@aws-sdk/client-lambda": "3.637.0", @@ -5549,8 +5549,8 @@ }, "node_modules/@adobe/spacecat-shared-rum-api-client": { "version": "2.8.0", - "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-rum-api-client/-/spacecat-shared-rum-api-client-2.8.0.tgz", - "integrity": "sha512-CNtQy6nYWErCJgG2YyFxej8hVBnoS8PItPNLvHRjEYXFpU9QhuoS+bSxcmDRbwRxMbHpAgK3XclddP6DFrKjDQ==", + "resolved": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?9b54c84d774a490e107c56c51db8d7a38562c8c9", + "integrity": "sha512-Q7jqs9u+pqaijp1ygQN3zKep8EZj8hlbGAMf+QhJHyRE9KzoKTb6INnq7sPEIP8FclmkmkuQ/sXO2UCUuPeiCA==", "dependencies": { "@adobe/fetch": "4.1.8", "@adobe/helix-shared-wrap": "2.0.2", diff --git a/package.json b/package.json index a8d3fd04..0a3927ee 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "2.8.0", + "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?9b54c84d774a490e107c56c51db8d7a38562c8c9", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@aws-sdk/client-lambda": "3.637.0", "@aws-sdk/credential-provider-node": "3.637.0", diff --git a/src/opportunities/opportunities.js b/src/opportunities/opportunities.js index 4eff2b43..c57d456b 100644 --- a/src/opportunities/opportunities.js +++ b/src/opportunities/opportunities.js @@ -16,6 +16,11 @@ import { AuditBuilder } from '../common/audit-builder.js'; import { getRUMDomainkey } from '../support/utils.js'; const DAYS = 30; +const OPPTY_QUERIES = [ + 'exp-opportunity/rage-click', + 'exp-opportunity/high-inorganic-high-bounce-rate', + 'exp-opportunity/high-organic-low-bounce-rate', +]; let log = console; @@ -40,13 +45,13 @@ export async function opportunitiesHandler(auditUrl, context, site) { interval: DAYS, granularity: 'hourly', }; - const experimentationHandlers = ['rageclick']; - const queryResults = await rumAPIClient.queryMulti(experimentationHandlers, options); + + const queryResults = await rumAPIClient.queryMulti(OPPTY_QUERIES, options); const auditData = { experimentationOpportunities: [], }; for (const queryResult of Object.keys(queryResults)) { - if (experimentationHandlers.includes(queryResult)) { + if (OPPTY_QUERIES.includes(queryResult)) { auditData.experimentationOpportunities.push(...queryResults[queryResult]); } } From 61bf4b5b92417190241ad7875e892aca946f1bb3 Mon Sep 17 00:00:00 2001 From: ekremney Date: Thu, 29 Aug 2024 17:21:41 +0200 Subject: [PATCH 2/5] feat: high bounce rate and low ctr opportunities --- package-lock.json | 6 +++--- package.json | 2 +- src/opportunities/opportunities.js | 6 +++--- test/audits/opportunities.test.js | 23 +++++++++++++---------- test/fixtures/opportunitiesdata.json | 22 +++++++++++++++++++++- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0b28f5dd..d64b8aca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?9b54c84d774a490e107c56c51db8d7a38562c8c9", + "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@adobe/spacecat-shared-utils": "1.19.6", "@aws-sdk/client-lambda": "3.637.0", @@ -5549,8 +5549,8 @@ }, "node_modules/@adobe/spacecat-shared-rum-api-client": { "version": "2.8.0", - "resolved": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?9b54c84d774a490e107c56c51db8d7a38562c8c9", - "integrity": "sha512-Q7jqs9u+pqaijp1ygQN3zKep8EZj8hlbGAMf+QhJHyRE9KzoKTb6INnq7sPEIP8FclmkmkuQ/sXO2UCUuPeiCA==", + "resolved": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", + "integrity": "sha512-BBqrCh7fP+eWWReMjpI6lyCnAKJGx3PFpY/1ivhqIZIONYN6NOOxqbCpyQgR+/yAFu2k9aprbGjum2lEC9FtRg==", "dependencies": { "@adobe/fetch": "4.1.8", "@adobe/helix-shared-wrap": "2.0.2", diff --git a/package.json b/package.json index 0a3927ee..0b4ed547 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?9b54c84d774a490e107c56c51db8d7a38562c8c9", + "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@aws-sdk/client-lambda": "3.637.0", "@aws-sdk/credential-provider-node": "3.637.0", diff --git a/src/opportunities/opportunities.js b/src/opportunities/opportunities.js index c57d456b..1d7b1008 100644 --- a/src/opportunities/opportunities.js +++ b/src/opportunities/opportunities.js @@ -17,9 +17,9 @@ import { getRUMDomainkey } from '../support/utils.js'; const DAYS = 30; const OPPTY_QUERIES = [ - 'exp-opportunity/rage-click', - 'exp-opportunity/high-inorganic-high-bounce-rate', - 'exp-opportunity/high-organic-low-bounce-rate', + 'rageclick', + 'high-inorganic-high-bounce-rate', + 'high-organic-low-ctr', ]; let log = console; diff --git a/test/audits/opportunities.test.js b/test/audits/opportunities.test.js index 22905dfb..bb2ef5df 100644 --- a/test/audits/opportunities.test.js +++ b/test/audits/opportunities.test.js @@ -93,17 +93,20 @@ describe('Opportunities Tests', () => { }; const auditData = await opportunitiesHandler(url, context, site); - expect(context.rumApiClient.queryMulti).calledWith( - ['rageclick'], - { - domain: 'https://abc.com', - domainkey: 'abc_dummy_key', - interval: 30, - granularity: 'hourly', - }, - ); + const expected = Object.values(opportunitiesData).flatMap((data) => data); + + expect(context.rumApiClient.queryMulti).calledWith([ + 'rageclick', + 'high-inorganic-high-bounce-rate', + 'high-organic-low-ctr', + ], { + domain: 'https://abc.com', + domainkey: 'abc_dummy_key', + interval: 30, + granularity: 'hourly', + }); expect( auditData.auditResult.experimentationOpportunities, - ).to.deep.equal(opportunitiesData.rageclick); + ).to.deep.equal(expected); }); }); diff --git a/test/fixtures/opportunitiesdata.json b/test/fixtures/opportunitiesdata.json index fde23dbf..f738a5ec 100644 --- a/test/fixtures/opportunitiesdata.json +++ b/test/fixtures/opportunitiesdata.json @@ -61,5 +61,25 @@ } ] } - ] + ], + "high-organic-low-ctr": [{ + "type": "high-organic-low-ctr", + "page": "https://abc.com/abc-adoption/account", + "screenshot": "", + "trackedPageKPIName": "Click Through Rate", + "trackedPageKPIValue": "0.14", + "pageViews": 2145, + "samples": 123, + "metrics": [] + }], + "high-inorganic-high-bounce-rate": [{ + "type": "high-inorganic-high-bounce-rate", + "page": "https://abc.com/abc-adoption/pricing", + "screenshot": "", + "trackedPageKPIName": "Bounce Rate", + "trackedPageKPIValue": 0.76, + "pageViews": 8839, + "samples": 89, + "metrics": [] + }] } From 2a2ab494bde6f937d8f8cff3215f5bf54d9d0aed Mon Sep 17 00:00:00 2001 From: ekremney Date: Tue, 3 Sep 2024 11:56:53 +0200 Subject: [PATCH 3/5] fix(exp-opportunities): bump the rumapi client version and rename the audit --- package-lock.json | 16 +++++----- package.json | 2 +- .../experimentation-opportunities.js} | 31 +++++-------------- src/index.js | 10 +++--- ... => experimentation-opportunities.test.js} | 4 +-- 5 files changed, 24 insertions(+), 39 deletions(-) rename src/{opportunities/opportunities.js => experimentation-opportunities/experimentation-opportunities.js} (63%) rename test/audits/{opportunities.test.js => experimentation-opportunities.test.js} (95%) diff --git a/package-lock.json b/package-lock.json index d64b8aca..162c3d97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", + "@adobe/spacecat-shared-rum-api-client": "2.9.0", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@adobe/spacecat-shared-utils": "1.19.6", "@aws-sdk/client-lambda": "3.637.0", @@ -5548,15 +5548,15 @@ } }, "node_modules/@adobe/spacecat-shared-rum-api-client": { - "version": "2.8.0", - "resolved": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", - "integrity": "sha512-BBqrCh7fP+eWWReMjpI6lyCnAKJGx3PFpY/1ivhqIZIONYN6NOOxqbCpyQgR+/yAFu2k9aprbGjum2lEC9FtRg==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-rum-api-client/-/spacecat-shared-rum-api-client-2.9.0.tgz", + "integrity": "sha512-VbtFFeQP/+/DJ9W+z09oMqLQfbGizmInScKv1xJs9di8lXRQislKofR/rC8Aak2Bu0d4odfdhjyywpxwLBggBg==", "dependencies": { "@adobe/fetch": "4.1.8", "@adobe/helix-shared-wrap": "2.0.2", "@adobe/helix-universal": "5.0.5", "@adobe/spacecat-shared-utils": "1.4.0", - "aws4": "1.13.1", + "aws4": "1.13.2", "d3-array": "3.2.4", "urijs": "^1.19.11" }, @@ -5663,9 +5663,9 @@ "license": "Apache-2.0" }, "node_modules/@adobe/spacecat-shared-rum-api-client/node_modules/aws4": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.13.1.tgz", - "integrity": "sha512-u5w79Rd7SU4JaIlA/zFqG+gOiuq25q5VLyZ8E+ijJeILuTxVzZgp2CaGw/UTw6pXYN9XMO9yiqj/nEHmhTG5CA==" + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.13.2.tgz", + "integrity": "sha512-lHe62zvbTB5eEABUVi/AwVh0ZKY9rMMDhmm+eeyuuUQbQ3+J+fONVQOZyj+DdrvD4BY33uYniyRJ4UJIaSKAfw==" }, "node_modules/@adobe/spacecat-shared-utils": { "version": "1.19.6", diff --git a/package.json b/package.json index 0b4ed547..26efbf15 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", + "@adobe/spacecat-shared-rum-api-client": "2.9.0", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@aws-sdk/client-lambda": "3.637.0", "@aws-sdk/credential-provider-node": "3.637.0", diff --git a/src/opportunities/opportunities.js b/src/experimentation-opportunities/experimentation-opportunities.js similarity index 63% rename from src/opportunities/opportunities.js rename to src/experimentation-opportunities/experimentation-opportunities.js index 1d7b1008..28f38417 100644 --- a/src/opportunities/opportunities.js +++ b/src/experimentation-opportunities/experimentation-opportunities.js @@ -10,7 +10,6 @@ * governing permissions and limitations under the License. */ -/* c8 ignore start */ import RUMAPIClient from '@adobe/spacecat-shared-rum-api-client'; import { AuditBuilder } from '../common/audit-builder.js'; import { getRUMDomainkey } from '../support/utils.js'; @@ -22,8 +21,6 @@ const OPPTY_QUERIES = [ 'high-organic-low-ctr', ]; -let log = console; - /** * Audit handler container for all the opportunities * @param {*} auditUrl @@ -32,10 +29,8 @@ let log = console; * @returns */ -export async function opportunitiesHandler(auditUrl, context, site) { - log = context.log; - log.info(`Received Opportunities audit request for ${auditUrl}`); - const startTime = process.hrtime(); +export async function handler(auditUrl, context, site) { + const { log } = context; const rumAPIClient = RUMAPIClient.createFrom(context); const domainkey = await getRUMDomainkey(site.getBaseURL(), context); @@ -47,28 +42,18 @@ export async function opportunitiesHandler(auditUrl, context, site) { }; const queryResults = await rumAPIClient.queryMulti(OPPTY_QUERIES, options); - const auditData = { - experimentationOpportunities: [], - }; - for (const queryResult of Object.keys(queryResults)) { - if (OPPTY_QUERIES.includes(queryResult)) { - auditData.experimentationOpportunities.push(...queryResults[queryResult]); - } - } - - const endTime = process.hrtime(startTime); - const elapsedSeconds = endTime[0] + endTime[1] / 1e9; - const formattedElapsed = elapsedSeconds.toFixed(2); + const experimentationOpportunities = Object.values(queryResults).flatMap((oppty) => oppty); - log.info(`Opportunities Audit is completed in ${formattedElapsed} seconds for ${auditUrl}`); + log.info(`Found ${experimentationOpportunities.length} many experimentation opportunites for ${auditUrl}`); return { - auditResult: auditData, + auditResult: { + experimentationOpportunities, + }, fullAuditRef: auditUrl, }; } export default new AuditBuilder() - .withRunner(opportunitiesHandler) + .withRunner(handler) .build(); -/* c8 ignore stop */ diff --git a/src/index.js b/src/index.js index a99c7086..19b7cfd2 100644 --- a/src/index.js +++ b/src/index.js @@ -29,7 +29,7 @@ import experimentation from './experimentation/handler.js'; import conversion from './conversion/handler.js'; import essExperimentationDaily from './experimentation-ess/daily.js'; import essExperimentationAll from './experimentation-ess/all.js'; -import opportunities from './opportunities/opportunities.js'; +import experimentationOpportunities from './experimentation-opportunities/experimentation-opportunities.js'; import costs from './costs/handler.js'; import structuredData from './structured-data/handler.js'; @@ -46,7 +46,7 @@ const HANDLERS = { conversion, 'experimentation-ess-daily': essExperimentationDaily, 'experimentation-ess-all': essExperimentationAll, - opportunities, + 'experimentation-opportunities': experimentationOpportunities, costs, 'structured-data': structuredData, dummy: (message) => ok(message), @@ -68,7 +68,7 @@ async function run(message, context) { const { log } = context; const { type, url } = message; - log.info(`Audit req received for url: ${url}`); + log.info(`Received ${type} audit request for: ${url}`); const handler = HANDLERS[type]; if (!handler) { @@ -82,11 +82,11 @@ async function run(message, context) { try { const result = await (typeof handler.run === 'function' ? handler.run(message, context) : handler(message, context)); - log.info(`Audit for ${type} completed in ${getElapsedSeconds(startTime)} seconds`); + log.info(`${type} audit for ${url} completed in ${getElapsedSeconds(startTime)} seconds`); return result; } catch (e) { - log.error(`Audit failed after ${getElapsedSeconds(startTime)} seconds`, e); + log.error(`${type} audit for ${url} failed after ${getElapsedSeconds(startTime)} seconds`, e); return internalServerError(); } } diff --git a/test/audits/opportunities.test.js b/test/audits/experimentation-opportunities.test.js similarity index 95% rename from test/audits/opportunities.test.js rename to test/audits/experimentation-opportunities.test.js index bb2ef5df..dfd17478 100644 --- a/test/audits/opportunities.test.js +++ b/test/audits/experimentation-opportunities.test.js @@ -16,7 +16,7 @@ import { expect, use } from 'chai'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import nock from 'nock'; -import { opportunitiesHandler } from '../../src/opportunities/opportunities.js'; +import { handler } from '../../src/experimentation-opportunities/experimentation-opportunities.js'; import { MockContextBuilder } from '../shared.js'; import opportunitiesData from '../fixtures/opportunitiesdata.json' assert { type: 'json' }; @@ -91,7 +91,7 @@ describe('Opportunities Tests', () => { const site = { getBaseURL: () => 'https://abc.com', }; - const auditData = await opportunitiesHandler(url, context, site); + const auditData = await handler(url, context, site); const expected = Object.values(opportunitiesData).flatMap((data) => data); From 08fcf882b2cddec3bc468476ecdd67ab42de2973 Mon Sep 17 00:00:00 2001 From: ekremney Date: Tue, 3 Sep 2024 13:55:32 +0200 Subject: [PATCH 4/5] fix(exp-opportunities): centralize wwwUrlResolver --- src/common/audit.js | 9 ++++++++- src/cwv/handler.js | 15 ++++----------- .../experimentation-opportunities.js | 2 ++ test/audits/cwv.test.js | 13 ++----------- test/common/audit.test.js | 16 ++++++++++++++-- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/common/audit.js b/src/common/audit.js index 546f0ecf..fbc21e41 100644 --- a/src/common/audit.js +++ b/src/common/audit.js @@ -10,8 +10,9 @@ * governing permissions and limitations under the License. */ -import { composeAuditURL } from '@adobe/spacecat-shared-utils'; +import { composeAuditURL, hasText } from '@adobe/spacecat-shared-utils'; import { ok } from '@adobe/spacecat-shared-http-utils'; +import URI from 'urijs'; import { retrieveSiteBySiteId } from '../utils/data-access.js'; export async function defaultMessageSender(resultMessage, context) { @@ -52,6 +53,12 @@ export async function defaultUrlResolver(site) { return composeAuditURL(site.getBaseURL()); } +export function wwwUrlResolver(site) { + const baseURL = site.getBaseURL(); + const uri = new URI(baseURL); + return hasText(uri.subdomain()) ? baseURL.replace(/https?:\/\//, '') : baseURL.replace(/https?:\/\//, 'www.'); +} + export async function noopUrlResolver(site) { return site.getBaseURL(); } diff --git a/src/cwv/handler.js b/src/cwv/handler.js index 2034eb04..3d6be775 100644 --- a/src/cwv/handler.js +++ b/src/cwv/handler.js @@ -11,25 +11,18 @@ */ import RUMAPIClient from '@adobe/spacecat-shared-rum-api-client'; -import URI from 'urijs'; -import { hasText } from '@adobe/spacecat-shared-utils'; import { getRUMDomainkey } from '../support/utils.js'; import { AuditBuilder } from '../common/audit-builder.js'; +import { wwwUrlResolver } from '../common/audit.js'; const DAILY_THRESHOLD = 1000; const INTERVAL = 7; // days -export function getAuditUrl(baseURL) { - const uri = new URI(baseURL); - return hasText(uri.subdomain()) ? baseURL.replace(/https?:\/\//, '') : baseURL.replace(/https?:\/\//, 'www.'); -} - export async function CWVRunner(auditUrl, context, site) { const rumAPIClient = RUMAPIClient.createFrom(context); const domainkey = await getRUMDomainkey(site.getBaseURL(), context); - const finalUrl = getAuditUrl(auditUrl); const options = { - domain: finalUrl, + domain: auditUrl, domainkey, interval: INTERVAL, granularity: 'hourly', @@ -44,11 +37,11 @@ export async function CWVRunner(auditUrl, context, site) { return { auditResult, - fullAuditRef: finalUrl, + fullAuditRef: auditUrl, }; } export default new AuditBuilder() - .withUrlResolver((site) => site.getBaseURL()) + .withUrlResolver(wwwUrlResolver) .withRunner(CWVRunner) .build(); diff --git a/src/experimentation-opportunities/experimentation-opportunities.js b/src/experimentation-opportunities/experimentation-opportunities.js index 28f38417..2c44b31e 100644 --- a/src/experimentation-opportunities/experimentation-opportunities.js +++ b/src/experimentation-opportunities/experimentation-opportunities.js @@ -13,6 +13,7 @@ import RUMAPIClient from '@adobe/spacecat-shared-rum-api-client'; import { AuditBuilder } from '../common/audit-builder.js'; import { getRUMDomainkey } from '../support/utils.js'; +import { wwwUrlResolver } from '../common/audit.js'; const DAYS = 30; const OPPTY_QUERIES = [ @@ -56,4 +57,5 @@ export async function handler(auditUrl, context, site) { export default new AuditBuilder() .withRunner(handler) + .withUrlResolver(wwwUrlResolver) .build(); diff --git a/test/audits/cwv.test.js b/test/audits/cwv.test.js index 664cef80..28080c1c 100644 --- a/test/audits/cwv.test.js +++ b/test/audits/cwv.test.js @@ -17,7 +17,7 @@ import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import nock from 'nock'; import { createSite } from '@adobe/spacecat-shared-data-access/src/models/site.js'; -import { CWVRunner, getAuditUrl } from '../../src/cwv/handler.js'; +import { CWVRunner } from '../../src/cwv/handler.js'; import { rumData } from '../fixtures/rum-data.js'; use(sinonChai); @@ -59,7 +59,7 @@ describe('Index Tests', () => { }); it('cwv audit runs rum api client cwv query', async () => { - const result = await CWVRunner('https://spacecat.com', context, site); + const result = await CWVRunner('www.spacecat.com', context, site); expect(result).to.deep.equal({ auditResult: { cwv: rumData.filter((data) => data.pageviews >= 7000), @@ -70,13 +70,4 @@ describe('Index Tests', () => { fullAuditRef: auditUrl, }); }); - - it('audit url calculated correctly', async () => { - expect(getAuditUrl('http://spacecat.com')).to.equal('www.spacecat.com'); - expect(getAuditUrl('https://spacecat.com')).to.equal('www.spacecat.com'); - expect(getAuditUrl('http://www.spacecat.com')).to.equal('www.spacecat.com'); - expect(getAuditUrl('https://www.spacecat.com')).to.equal('www.spacecat.com'); - expect(getAuditUrl('http://blog.spacecat.com')).to.equal('blog.spacecat.com'); - expect(getAuditUrl('https://blog.spacecat.com')).to.equal('blog.spacecat.com'); - }); }); diff --git a/test/common/audit.test.js b/test/common/audit.test.js index a3078ab4..d1296366 100644 --- a/test/common/audit.test.js +++ b/test/common/audit.test.js @@ -21,10 +21,13 @@ import { createOrganization } from '@adobe/spacecat-shared-data-access/src/model import { createConfiguration } from '@adobe/spacecat-shared-data-access/src/models/configuration.js'; import { composeAuditURL, prependSchema } from '@adobe/spacecat-shared-utils'; import { - defaultMessageSender, defaultOrgProvider, + defaultMessageSender, + defaultOrgProvider, defaultPersister, defaultSiteProvider, - defaultUrlResolver, noopUrlResolver, + defaultUrlResolver, + noopUrlResolver, + wwwUrlResolver, } from '../../src/common/audit.js'; import { AuditBuilder } from '../../src/common/audit-builder.js'; import { MockContextBuilder } from '../shared.js'; @@ -326,4 +329,13 @@ describe('Audit tests', () => { expect(context.sqs.sendMessage).to.have.been.calledOnce; expect(context.sqs.sendMessage).to.have.been.calledWith(queueUrl, expectedMessage); }); + + it('wwwUrlResolver calculates audit urls correctly', async () => { + expect(wwwUrlResolver(createSite({ baseURL: 'http://spacecat.com' }))).to.equal('www.spacecat.com'); + expect(wwwUrlResolver(createSite({ baseURL: 'https://spacecat.com' }))).to.equal('www.spacecat.com'); + expect(wwwUrlResolver(createSite({ baseURL: 'http://www.spacecat.com' }))).to.equal('www.spacecat.com'); + expect(wwwUrlResolver(createSite({ baseURL: 'https://www.spacecat.com' }))).to.equal('www.spacecat.com'); + expect(wwwUrlResolver(createSite({ baseURL: 'http://blog.spacecat.com' }))).to.equal('blog.spacecat.com'); + expect(wwwUrlResolver(createSite({ baseURL: 'https://blog.spacecat.com' }))).to.equal('blog.spacecat.com'); + }); }); From 3c839ed6f34aecc850f91d23d496dcf96050ef9a Mon Sep 17 00:00:00 2001 From: ekremney Date: Tue, 3 Sep 2024 13:58:05 +0200 Subject: [PATCH 5/5] fix(exp-opportunities): package-lock.json --- package-lock.json | 161 +++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 101 deletions(-) diff --git a/package-lock.json b/package-lock.json index 162c3d97..e4bb095b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@adobe/spacecat-audit-worker", - "version": "1.29.1", + "version": "1.29.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@adobe/spacecat-audit-worker", - "version": "1.29.1", + "version": "1.29.2", "license": "Apache-2.0", "dependencies": { "@adobe/fetch": "4.1.8", @@ -36,13 +36,13 @@ "@adobe/helix-universal": "5.0.5", "@adobe/semantic-release-coralogix": "1.1.31", "@adobe/semantic-release-skms-cmr": "1.1.2", - "@redocly/cli": "1.21.0", + "@redocly/cli": "1.22.1", "@semantic-release/changelog": "6.0.3", "@semantic-release/exec": "6.0.3", "@semantic-release/git": "10.0.1", "@semantic-release/npm": "12.0.1", - "@typescript-eslint/eslint-plugin": "8.2.0", - "@typescript-eslint/parser": "8.2.0", + "@typescript-eslint/eslint-plugin": "8.3.0", + "@typescript-eslint/parser": "8.3.0", "c8": "10.1.2", "chai": "5.1.1", "chai-as-promised": "8.0.0", @@ -20363,13 +20363,12 @@ } }, "node_modules/@redocly/cli": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-1.21.0.tgz", - "integrity": "sha512-KPCHWrTXnIV01rgpgwnyQuwKhSol5pnNor20f6/szVrUcZ+vRCqKeZDR1CSMBYIXEsi0AknLV7WR8BCYyfYbog==", + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/@redocly/cli/-/cli-1.22.1.tgz", + "integrity": "sha512-fGBj3KH32JH9Kg4Y3DQ2iF5jfpjT7T5ypA3JOpJcwGZTI/krDzrSxOb7ArX0HCATCBCobkWzDynHBF03j9oPvw==", "dev": true, - "license": "MIT", "dependencies": { - "@redocly/openapi-core": "1.21.0", + "@redocly/openapi-core": "1.22.1", "abort-controller": "^3.0.0", "chokidar": "^3.5.1", "colorette": "^1.2.0", @@ -20533,21 +20532,19 @@ } }, "node_modules/@redocly/config": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.9.0.tgz", - "integrity": "sha512-rRd0pSiPC68AQGud2VbrHqUov1VHospfcYE2pFYmGYfZhzZfHBSiVaeiTY+CZmrhf5RB9aVdOHRCm25Vb6GFkQ==", - "dev": true, - "license": "MIT" + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.10.1.tgz", + "integrity": "sha512-H3LnKVGzOaxskwJu8pmJYwBOWjP61qOK7TuTrbafqArDVckE06fhA6l0nO4KvBbjLPjy1Al7UnlxOu23V4Nl0w==", + "dev": true }, "node_modules/@redocly/openapi-core": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.21.0.tgz", - "integrity": "sha512-8KwL/0jiQBSJMNp1lSMLM1UeV2FW9DdqcjO0J9s5w7yL7ZN+SNh11MTp0zU4om/pGYExQ64hxLM/+7VdjznHRQ==", + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-1.22.1.tgz", + "integrity": "sha512-pjr456gJzrbwPvBjFKlWOd9nZEcr/dp6XSH0c8ijWGWv5K+V0vpUUy2zaTAVsFAoCydx1miEoOcbLhWQ9WC2nw==", "dev": true, - "license": "MIT", "dependencies": { "@redocly/ajv": "^8.11.0", - "@redocly/config": "^0.9.0", + "@redocly/config": "^0.10.1", "colorette": "^1.2.0", "https-proxy-agent": "^7.0.4", "js-levenshtein": "^1.1.6", @@ -22549,16 +22546,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.2.0.tgz", - "integrity": "sha512-02tJIs655em7fvt9gps/+4k4OsKULYGtLBPJfOsmOq1+3cdClYiF0+d6mHu6qDnTcg88wJBkcPLpQhq7FyDz0A==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.3.0.tgz", + "integrity": "sha512-FLAIn63G5KH+adZosDYiutqkOkYEx0nvcwNNfJAf+c7Ae/H35qWwTYvPZUKFj5AS+WfHG/WJJfWnDnyNUlp8UA==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.2.0", - "@typescript-eslint/type-utils": "8.2.0", - "@typescript-eslint/utils": "8.2.0", - "@typescript-eslint/visitor-keys": "8.2.0", + "@typescript-eslint/scope-manager": "8.3.0", + "@typescript-eslint/type-utils": "8.3.0", + "@typescript-eslint/utils": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -22582,15 +22579,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.2.0.tgz", - "integrity": "sha512-j3Di+o0lHgPrb7FxL3fdEy6LJ/j2NE8u+AP/5cQ9SKb+JLH6V6UHDqJ+e0hXBkHP1wn1YDFjYCS9LBQsZDlDEg==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.3.0.tgz", + "integrity": "sha512-h53RhVyLu6AtpUzVCYLPhZGL5jzTD9fZL+SYf/+hYOx2bDkyQXztXSc4tbvKYHzfMXExMLiL9CWqJmVz6+78IQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.2.0", - "@typescript-eslint/types": "8.2.0", - "@typescript-eslint/typescript-estree": "8.2.0", - "@typescript-eslint/visitor-keys": "8.2.0", + "@typescript-eslint/scope-manager": "8.3.0", + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/typescript-estree": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0", "debug": "^4.3.4" }, "engines": { @@ -22610,13 +22607,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.2.0.tgz", - "integrity": "sha512-OFn80B38yD6WwpoHU2Tz/fTz7CgFqInllBoC3WP+/jLbTb4gGPTy9HBSTsbDWkMdN55XlVU0mMDYAtgvlUspGw==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.3.0.tgz", + "integrity": "sha512-mz2X8WcN2nVu5Hodku+IR8GgCOl4C0G/Z1ruaWN4dgec64kDBabuXyPAr+/RgJtumv8EEkqIzf3X2U5DUKB2eg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.2.0", - "@typescript-eslint/visitor-keys": "8.2.0" + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -22627,13 +22624,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.2.0.tgz", - "integrity": "sha512-g1CfXGFMQdT5S+0PSO0fvGXUaiSkl73U1n9LTK5aRAFnPlJ8dLKkXr4AaLFvPedW8lVDoMgLLE3JN98ZZfsj0w==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.3.0.tgz", + "integrity": "sha512-wrV6qh//nLbfXZQoj32EXKmwHf4b7L+xXLrP3FZ0GOUU72gSvLjeWUl5J5Ue5IwRxIV1TfF73j/eaBapxx99Lg==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.2.0", - "@typescript-eslint/utils": "8.2.0", + "@typescript-eslint/typescript-estree": "8.3.0", + "@typescript-eslint/utils": "8.3.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -22651,9 +22648,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.2.0.tgz", - "integrity": "sha512-6a9QSK396YqmiBKPkJtxsgZZZVjYQ6wQ/TlI0C65z7vInaETuC6HAHD98AGLC8DyIPqHytvNuS8bBVvNLKyqvQ==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.3.0.tgz", + "integrity": "sha512-y6sSEeK+facMaAyixM36dQ5NVXTnKWunfD1Ft4xraYqxP0lC0POJmIaL/mw72CUMqjY9qfyVfXafMeaUj0noWw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -22664,15 +22661,15 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.2.0.tgz", - "integrity": "sha512-kiG4EDUT4dImplOsbh47B1QnNmXSoUqOjWDvCJw/o8LgfD0yr7k2uy54D5Wm0j4t71Ge1NkynGhpWdS0dEIAUA==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.3.0.tgz", + "integrity": "sha512-Mq7FTHl0R36EmWlCJWojIC1qn/ZWo2YiWYc1XVtasJ7FIgjo0MVv9rZWXEE7IK2CGrtwe1dVOxWwqXUdNgfRCA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.2.0", - "@typescript-eslint/visitor-keys": "8.2.0", + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0", "debug": "^4.3.4", - "globby": "^11.1.0", + "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", @@ -22707,15 +22704,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.2.0.tgz", - "integrity": "sha512-O46eaYKDlV3TvAVDNcoDzd5N550ckSe8G4phko++OCSC1dYIb9LTc3HDGYdWqWIAT5qDUKphO6sd9RrpIJJPfg==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.3.0.tgz", + "integrity": "sha512-F77WwqxIi/qGkIGOGXNBLV7nykwfjLsdauRB/DOFPdv6LTF3BHHkBpq81/b5iMPSF055oO2BiivDJV4ChvNtXA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.2.0", - "@typescript-eslint/types": "8.2.0", - "@typescript-eslint/typescript-estree": "8.2.0" + "@typescript-eslint/scope-manager": "8.3.0", + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/typescript-estree": "8.3.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -22729,12 +22726,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.2.0.tgz", - "integrity": "sha512-sbgsPMW9yLvS7IhCi8IpuK1oBmtbWUNP+hBdwl/I9nzqVsszGnNGti5r9dUtF5RLivHUFFIdRvLiTsPhzSyJ3Q==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.3.0.tgz", + "integrity": "sha512-RmZwrTbQ9QveF15m/Cl28n0LXD6ea2CjkhH5rQ55ewz3H24w+AMCJHPVYaZ8/0HoG8Z3cLLFFycRXxeO2tz9FA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.2.0", + "@typescript-eslint/types": "8.3.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -23203,15 +23200,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/array.prototype.filter": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/array.prototype.filter/-/array.prototype.filter-1.0.4.tgz", @@ -26569,26 +26557,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, - "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/google-auth-library": { "version": "9.14.0", "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.14.0.tgz", @@ -34605,15 +34573,6 @@ "node": ">=8" } }, - "node_modules/slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/slice-ansi": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-5.0.0.tgz",