@adobe/spacecat-shared-data-access 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.13.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.12.0...@adobe/spacecat-shared-data-access-v1.13.0) (2024-01-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * introduce default config for organic-keywords report (SITES-19317) ([#118](https://github.com/adobe/spacecat-shared/issues/118)) ([4301556](https://github.com/adobe/spacecat-shared/commit/430155645e1452760bf2818d70a0faae2fb8db12))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.12.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.11.0...@adobe/spacecat-shared-data-access-v1.12.0) (2024-01-29)
9
+
10
+
11
+ ### Features
12
+
13
+ * add getSitesByOrganizationIDWithLatestAudits query ([d3a8f8c](https://github.com/adobe/spacecat-shared/commit/d3a8f8cc2148229aecec3df277e298a3f0746865))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.11.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.10.5...@adobe/spacecat-shared-data-access-v1.11.0) (2024-01-29)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -15,6 +15,7 @@ import { Base } from './base.js';
15
15
 
16
16
  export const AUDIT_TYPE_404 = '404';
17
17
  export const AUDIT_TYPE_BROKEN_BACKLINKS = 'broken-backlinks';
18
+ export const AUDIT_TYPE_ORGANIC_KEYWORDS = 'organic-keywords';
18
19
  export const AUDIT_TYPE_CWV = 'cwv';
19
20
  export const AUDIT_TYPE_LHS_DESKTOP = 'lhs-desktop';
20
21
  export const AUDIT_TYPE_LHS_MOBILE = 'lhs-mobile';
@@ -24,6 +25,7 @@ const EXPIRES_IN_DAYS = 30;
24
25
  const AUDIT_TYPE_PROPERTIES = {
25
26
  [AUDIT_TYPE_404]: [],
26
27
  [AUDIT_TYPE_BROKEN_BACKLINKS]: [],
28
+ [AUDIT_TYPE_ORGANIC_KEYWORDS]: [],
27
29
  [AUDIT_TYPE_CWV]: [],
28
30
  [AUDIT_TYPE_LHS_DESKTOP]: ['performance', 'seo', 'accessibility', 'best-practices'],
29
31
  [AUDIT_TYPE_LHS_MOBILE]: ['performance', 'seo', 'accessibility', 'best-practices'],
@@ -11,16 +11,21 @@
11
11
  */
12
12
 
13
13
  import AuditConfigType from './audit-config-type.js';
14
- import { AUDIT_TYPE_BROKEN_BACKLINKS } from '../audit.js';
14
+ import {
15
+ AUDIT_TYPE_BROKEN_BACKLINKS,
16
+ AUDIT_TYPE_ORGANIC_KEYWORDS,
17
+ } from '../audit.js';
15
18
 
16
19
  const AUDIT_TYPE_DISABLED_DEFAULTS = {
17
20
  [AUDIT_TYPE_BROKEN_BACKLINKS]: true,
21
+ [AUDIT_TYPE_ORGANIC_KEYWORDS]: true,
18
22
  };
19
23
 
20
24
  function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) {
21
25
  if (!auditTypeConfigs || Object.keys(auditTypeConfigs).length === 0) {
22
26
  return {
23
27
  [AUDIT_TYPE_BROKEN_BACKLINKS]: AuditConfigType({ disabled: true }),
28
+ [AUDIT_TYPE_ORGANIC_KEYWORDS]: AuditConfigType({ disabled: true }),
24
29
  };
25
30
  }
26
31
  return Object.entries(auditTypeConfigs || {}).reduce((acc, [key, value]) => {
@@ -266,6 +266,51 @@ export const getSitesByOrganizationID = async (
266
266
  return dynamoItems.map((dynamoItem) => SiteDto.fromDynamoItem(dynamoItem));
267
267
  };
268
268
 
269
+ /**
270
+ * Retrieves sites by organizationId with their latest audit. Sites without a latest
271
+ * audit will not be included in the result.
272
+ * The sites are sorted by their latest audit scores in ascending order by default.
273
+ * The sortAuditsAscending parameter can be used to change the sort order.
274
+ * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
275
+ * @param {DataAccessConfig} config - The data access config.
276
+ * @param {Logger} log - The logger.
277
+ * @param {string} auditType - The type of audits to retrieve for the sites.
278
+ * @param {string} organizationId - The organizationId to retrieve the sites.
279
+ * @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
280
+ * ascending order.
281
+ * to retrieve.
282
+ * @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of sites with their
283
+ * latest audit.
284
+ */
285
+ export const getSitesByOrganizationIDWithLatestAudits = async (
286
+ dynamoClient,
287
+ config,
288
+ log,
289
+ organizationId,
290
+ auditType,
291
+ sortAuditsAscending = true,
292
+ ) => {
293
+ const [sites, latestAudits] = await Promise.all([
294
+ getSitesByOrganizationID(dynamoClient, config, organizationId),
295
+ getLatestAudits(dynamoClient, config, log, auditType, sortAuditsAscending),
296
+ ]);
297
+
298
+ const sitesMap = new Map(sites.map((site) => [site.getId(), site]));
299
+ const orderedSites = [];
300
+
301
+ // Append just sites with a latest audit in the sorted order
302
+ latestAudits.forEach((audit) => {
303
+ const site = sitesMap.get(audit.getSiteId());
304
+ if (site) {
305
+ site.setAudits([audit]);
306
+ orderedSites.push(site);
307
+ sitesMap.delete(site.getId()); // Remove the site from the map to avoid adding it again
308
+ }
309
+ });
310
+
311
+ return orderedSites;
312
+ };
313
+
269
314
  /**
270
315
  * Retrieves a site by its ID.
271
316
  *
@@ -19,7 +19,7 @@ import {
19
19
  getSiteByID,
20
20
  getSites,
21
21
  getSitesByDeliveryType,
22
- getSitesByOrganizationID,
22
+ getSitesByOrganizationID, getSitesByOrganizationIDWithLatestAudits,
23
23
  getSitesToAudit,
24
24
  getSitesWithLatestAudit,
25
25
  removeSite,
@@ -58,6 +58,18 @@ export const siteFunctions = (dynamoClient, config, log) => ({
58
58
  sortAuditsAscending,
59
59
  deliveryType,
60
60
  ),
61
+ getSitesByOrganizationIDWithLatestAudits: (
62
+ organizationId,
63
+ auditType,
64
+ sortAuditsAscending,
65
+ ) => getSitesByOrganizationIDWithLatestAudits(
66
+ dynamoClient,
67
+ config,
68
+ log,
69
+ organizationId,
70
+ auditType,
71
+ sortAuditsAscending,
72
+ ),
61
73
  getSiteByBaseURL: (baseUrl) => getSiteByBaseURL(
62
74
  dynamoClient,
63
75
  config,