@adobe/spacecat-shared-data-access 1.1.5 → 1.2.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.2.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.1.6...@adobe/spacecat-shared-data-access-v1.2.0) (2023-12-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * introduce getSiteByID ([#36](https://github.com/adobe-rnd/spacecat-shared/issues/36)) ([5677f76](https://github.com/adobe-rnd/spacecat-shared/commit/5677f76d11d97f2a2afd878e0ada7cad22fd1f03))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.1.6](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.1.5...@adobe/spacecat-shared-data-access-v1.1.6) (2023-12-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * use getItem for latest audit ([#35](https://github.com/adobe-rnd/spacecat-shared/issues/35)) ([6e4a87e](https://github.com/adobe-rnd/spacecat-shared/commit/6e4a87ea2d515f632b34278a8cc1ffd51d692a16))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.1.5](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.1.4...@adobe/spacecat-shared-data-access-v1.1.5) (2023-12-05)
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.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -81,6 +81,9 @@ export interface DataAccess {
81
81
  baseUrl: string,
82
82
  auditType: string,
83
83
  ) => Promise<Site | null>;
84
+ getSiteByID: (
85
+ siteId: string,
86
+ ) => Promise<Site | null>;
84
87
  addSite: (
85
88
  siteData: object,
86
89
  ) => Promise<Site>;
@@ -151,17 +151,12 @@ export const getLatestAuditForSite = async (
151
151
  siteId,
152
152
  auditType,
153
153
  ) => {
154
- const latestAudit = await dynamoClient.query({
155
- TableName: config.tableNameLatestAudits,
156
- KeyConditionExpression: 'siteId = :siteId AND auditType = :auditType',
157
- ExpressionAttributeValues: {
158
- ':siteId': siteId,
159
- ':auditType': `${auditType}`,
160
- },
161
- Limit: 1,
154
+ const latestAudit = await dynamoClient.getItem(config.tableNameLatestAudits, {
155
+ siteId,
156
+ auditType,
162
157
  });
163
158
 
164
- return latestAudit.length > 0 ? AuditDto.fromDynamoItem(latestAudit[0]) : null;
159
+ return latestAudit ? AuditDto.fromDynamoItem(latestAudit) : null;
165
160
  };
166
161
 
167
162
  /**
@@ -42,16 +42,16 @@ export const getSites = async (dynamoClient, config) => {
42
42
  };
43
43
 
44
44
  /**
45
- * Retrieves a list of base URLs for all sites.
45
+ * Retrieves a list of site IDs of all sites.
46
46
  *
47
47
  * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
48
48
  * @param {DataAccessConfig} config - The data access config.
49
- * @returns {Promise<Array<string>>} A promise that resolves to an array of base URLs for all sites.
49
+ * @returns {Promise<Array<string>>} A promise that resolves to an array of site IDs of all sites.
50
50
  */
51
51
  export const getSitesToAudit = async (dynamoClient, config) => {
52
52
  const sites = await getSites(dynamoClient, config);
53
53
 
54
- return sites.map((site) => site.getBaseURL());
54
+ return sites.map((site) => site.getId());
55
55
  };
56
56
 
57
57
  /**
@@ -117,11 +117,7 @@ export const getSiteByBaseURL = async (
117
117
  Limit: 1,
118
118
  });
119
119
 
120
- if (dynamoItems.length === 0) {
121
- return null;
122
- }
123
-
124
- return SiteDto.fromDynamoItem(dynamoItems[0]);
120
+ return dynamoItems.length > 0 ? SiteDto.fromDynamoItem(dynamoItems[0]) : null;
125
121
  };
126
122
 
127
123
  /**
@@ -209,6 +205,27 @@ export const getSiteByBaseURLWithLatestAudit = async (
209
205
  auditType,
210
206
  ) => getSiteByBaseURLWithAuditInfo(dynamoClient, config, log, baseUrl, auditType, true);
211
207
 
208
+ /**
209
+ * Retrieves a site by its ID.
210
+ *
211
+ * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
212
+ * @param {DataAccessConfig} config - The data access config.
213
+ * @param {Logger} log - The logger.
214
+ * @param {string} siteId - The ID of the site to retrieve.
215
+ * @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object if found,
216
+ * otherwise null.
217
+ */
218
+ export const getSiteByID = async (
219
+ dynamoClient,
220
+ config,
221
+ log,
222
+ siteId,
223
+ ) => {
224
+ const dynamoItem = await dynamoClient.getItem(config.tableNameSites, { id: siteId });
225
+
226
+ return isObject(dynamoItem) ? SiteDto.fromDynamoItem(dynamoItem) : null;
227
+ };
228
+
212
229
  /**
213
230
  * Adds a site.
214
231
  *
@@ -16,6 +16,7 @@ import {
16
16
  getSiteByBaseURLWithAuditInfo,
17
17
  getSiteByBaseURLWithAudits,
18
18
  getSiteByBaseURLWithLatestAudit,
19
+ getSiteByID,
19
20
  getSites,
20
21
  getSitesToAudit,
21
22
  getSitesWithLatestAudit, removeSite,
@@ -44,6 +45,12 @@ export const siteFunctions = (dynamoClient, config, log) => ({
44
45
  log,
45
46
  baseUrl,
46
47
  ),
48
+ getSiteByID: (siteId) => getSiteByID(
49
+ dynamoClient,
50
+ config,
51
+ log,
52
+ siteId,
53
+ ),
47
54
  getSiteByBaseURLWithAuditInfo: (baseUrl, auditType, latestOnly) => getSiteByBaseURLWithAuditInfo(
48
55
  dynamoClient,
49
56
  config,