Skip to content

Commit

Permalink
Merge branch 'main' into feat/alt-text-audit
Browse files Browse the repository at this point in the history
* main:
  chore(release): 1.52.14 [skip ci]
  fix(deps): update adobe fixes (#662)
  docs: updating README for adding opportunities and suggestions (#657)
  chore(release): 1.52.13 [skip ci]
  fix(deps): update adobe fixes (#661)
  chore(release): 1.52.12 [skip ci]
  fix(deps): update external fixes (#660)
  chore(release): 1.52.11 [skip ci]
  fix(deps): update dependency @adobe/spacecat-shared-data-access to v2.2.1 (#658)
  chore(release): 1.52.10 [skip ci]
  fix: track just redirects and not found oppties (#654)
  • Loading branch information
Josep Lopez committed Feb 17, 2025
2 parents d975fb8 + f714bf9 commit 1c7d349
Show file tree
Hide file tree
Showing 6 changed files with 2,826 additions and 1,236 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
## [1.52.14](https://github.com/adobe/spacecat-audit-worker/compare/v1.52.13...v1.52.14) (2025-02-17)


### Bug Fixes

* **deps:** update adobe fixes ([#662](https://github.com/adobe/spacecat-audit-worker/issues/662)) ([cddb981](https://github.com/adobe/spacecat-audit-worker/commit/cddb98168ef9bebc6694561b4237f11b16ff0e77))

## [1.52.13](https://github.com/adobe/spacecat-audit-worker/compare/v1.52.12...v1.52.13) (2025-02-16)


### Bug Fixes

* **deps:** update adobe fixes ([#661](https://github.com/adobe/spacecat-audit-worker/issues/661)) ([2051c9f](https://github.com/adobe/spacecat-audit-worker/commit/2051c9f90bcbfad78e47e6adc003585c6e6407d2))

## [1.52.12](https://github.com/adobe/spacecat-audit-worker/compare/v1.52.11...v1.52.12) (2025-02-16)


### Bug Fixes

* **deps:** update external fixes ([#660](https://github.com/adobe/spacecat-audit-worker/issues/660)) ([40947a6](https://github.com/adobe/spacecat-audit-worker/commit/40947a64b1b34a3dd234a8e5a5b92eae0ff44e06))

## [1.52.11](https://github.com/adobe/spacecat-audit-worker/compare/v1.52.10...v1.52.11) (2025-02-14)


### Bug Fixes

* **deps:** update dependency @adobe/spacecat-shared-data-access to v2.2.1 ([#658](https://github.com/adobe/spacecat-audit-worker/issues/658)) ([aa8c3ce](https://github.com/adobe/spacecat-audit-worker/commit/aa8c3ce3f7a338f28a0864e0d43a2567efe16d27))

## [1.52.10](https://github.com/adobe/spacecat-audit-worker/compare/v1.52.9...v1.52.10) (2025-02-14)


### Bug Fixes

* track just redirects and not found oppties ([#654](https://github.com/adobe/spacecat-audit-worker/issues/654)) ([62cddc6](https://github.com/adobe/spacecat-audit-worker/commit/62cddc6497c08a91b19cbdf30fee91a81280187c))

## [1.52.9](https://github.com/adobe/spacecat-audit-worker/compare/v1.52.8...v1.52.9) (2025-02-12)


Expand Down
126 changes: 56 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $ npm test
$ npm run lint
```

## Message Body Formats
## Message Body Formats

Audit worker consumes the `AUDIT_JOBS_QUEUE` queue, performs the requested audit, then queues the result to `AUDIT_RESULTS_QUEUE` for the interested parties to consume later on.

Expand Down Expand Up @@ -109,7 +109,7 @@ To create a new audit, you'll need to create an audit handler function. This fun

```js
export async function auditRunner(url, context) {

// your audit logic goes here...

return {
Expand All @@ -130,7 +130,7 @@ All audits share common components, such as persisting audit results to a databa

```js
export async function auditRunner(url, context) {

// your audit logic goes here...

return {
Expand All @@ -141,7 +141,7 @@ export async function auditRunner(url, context) {

export async function differentUrlResolver(site) {
// logic to override to default behavior of the audit step

return 'url';
}

Expand All @@ -158,7 +158,7 @@ Using a noop messageSender, audit results might not be sent to the audit results

```js
export async function auditRunner(url, context) {

// your audit logic goes here...

return {
Expand Down Expand Up @@ -195,7 +195,7 @@ Here's the full example:

```js
export async function auditRunner(url, context) {

// your audit logic goes here...

return {
Expand All @@ -218,81 +218,67 @@ export default new AuditBuilder()
```

### How to add Opportunities and Suggestions
```js
import { syncSuggestions } from '../utils/data-access.js';

export async function auditRunner(url, context) {
In the handler, the `opportunityAndSuggestions` function is responsible for converting audit data into an opportunity and synchronizing suggestions.

// your audit logic goes here...
This function utilizes the `convertToOpportunity` function to create or update an opportunity based on the audit data and type.

return {
auditResult: results,
fullAuditRef: baseURL,
};
}
The `buildKey` function is used to generate a unique key for each suggestion based on specific properties of the audit data.

async function convertToOpportunity(auditUrl, auditData, context) {
const { dataAccess, log } = context;

const opportunities = await dataAccess.Opportunity.allBySiteIdAndStatus(auditData.siteId, 'NEW');
let opportunity = opportunities.find((oppty) => oppty.getType() === 'audit-type');

if (!opportunity) {
const opportunityData = {
siteId: auditData.siteId,
auditId: auditData.id,
runbook: 'link-to-runbook',
type: 'audit-type',
origin: 'AUTOMATION',
title: 'Opportunity Title',
description: 'Opportunity Description',
guidance: {
steps: [
'Step 1',
'Step 2',
],
},
tags: ['tag1', 'tag2'],
};
try {
opportunity = await dataAccess.Opportunity.create(opportunityData);
} catch (e) {
log.error(`Failed to create new opportunity for siteId ${auditData.siteId} and auditId ${auditData.id}: ${e.message}`);
throw e;
}
} else {
opportunity.setAuditId(auditData.id);
await opportunity.save();
}

// this logic changes based on the audit type
const buildKey = (auditData) => `${auditData.property}|${auditData.anotherProperty}`;

await syncSuggestions({
opportunity,
newData: auditData,
buildKey,
mapNewSuggestion: (issue) => ({
opportunityId: opportunity.getId(),
type: 'SUGGESTION_TYPE',
rank: issue.rankMetric,
// data changes based on the audit type
data: {
property: issue.property,
anotherProperty: issue.anotherProperty,
},
}),
log,
});
}
It then uses the `syncSuggestions` function to map new suggestions to the opportunity and synchronize them.

```js
import { syncSuggestions } from '../utils/data-access.js';
import { convertToOpportunity } from '../common/opportunity.js';
import { createOpportunityData } from './opportunity-data-mapper.js';

export async function opportunityAndSuggestions(auditUrl, auditData, context) {
const opportunity = await convertToOpportunity(
auditUrl,
auditData,
context,
createOpportunityData,
auditType,
);

const { log } = context;

// buildKey and SyncSuggestions logic based on the auditType goes here...
)};
```
```js
export default new AuditBuilder()
.withRunner(auditRunner)
.withPostProcessors([ convertToOpportunity ])
.withPostProcessors([opportunityAndSuggestions])
.build();
```


The logic for converting to an opportunity is in `common/opportunity.js`. The function `convertToOpportunity` is used to create a new opportunity or update an existing one based on the audit type. The function takes the audit URL, audit data, context, createOpportunityData, auditType, and props as arguments. It first fetches the opportunities for the site. If the opportunity is not found, it creates a new one. If the opportunity is found, it updates the existing one with the new data. The function returns the opportunity entity.


How to map the opportunity data in the handler's `opportunity-data-mapper.js` file:

```js
export function createOpportunityData(parameters) {
return {
runbook: 'runbook',
origin: 'origin',
title: 'title',
description: 'description',
guidance: {
steps: [
'step1',
'step2',
],
},
tags: ['tag1'],
data: {data},
};
}
```


### How to add auto-suggest to an audit
A new auto-suggest feature can be added as a post processor step to the existing audit.

Expand Down
Loading

0 comments on commit 1c7d349

Please sign in to comment.