@adobe/spacecat-shared-data-access 1.2.1 → 1.2.3

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.3](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.2...@adobe/spacecat-shared-data-access-v1.2.3) (2023-12-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * allow sorting for get audits for site ([#41](https://github.com/adobe-rnd/spacecat-shared/issues/41)) ([3664c97](https://github.com/adobe-rnd/spacecat-shared/commit/3664c97bd63d4f10e260582455e3763da60399dd))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.2.2](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.1...@adobe/spacecat-shared-data-access-v1.2.2) (2023-12-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * allow update of github URL ([#40](https://github.com/adobe-rnd/spacecat-shared/issues/40)) ([21da989](https://github.com/adobe-rnd/spacecat-shared/commit/21da9893fcb9c971c1c6a4e1271133188351c155))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.2.1](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.0...@adobe/spacecat-shared-data-access-v1.2.1) (2023-12-07)
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.2.1",
3
+ "version": "1.2.3",
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
@@ -34,13 +34,15 @@ export interface Site {
34
34
  isLive: () => boolean;
35
35
  setAudits: (audits: Audit[]) => Site;
36
36
  toggleLive: () => Site;
37
+ updateGitHubURL: (gitHubURL: string) => Site;
37
38
  updateImsOrgId: (imsOrgId: string) => Site;
38
39
  }
39
40
 
40
41
  export interface DataAccess {
41
42
  getAuditsForSite: (
42
43
  siteId: string,
43
- auditType?: string
44
+ auditType?: string,
45
+ ascending?: boolean,
44
46
  ) => Promise<Audit[]>;
45
47
  getLatestAuditForSite: (
46
48
  siteId: string,
@@ -65,6 +65,27 @@ const Site = (data = {}) => {
65
65
  return self;
66
66
  }; */
67
67
 
68
+ /**
69
+ * Updates the GitHub URL belonging to the site.
70
+ * @param {string} gitHubURL - The GitHub URL.
71
+ * @return {Base} The updated site.
72
+ */
73
+ self.updateGitHubURL = (gitHubURL) => {
74
+ if (!isValidUrl(gitHubURL)) {
75
+ throw new Error('GitHub URL must be a valid URL');
76
+ }
77
+
78
+ self.state.gitHubURL = gitHubURL;
79
+ self.touch();
80
+
81
+ return self;
82
+ };
83
+
84
+ /**
85
+ * Updates the IMS Org ID belonging to the site.
86
+ * @param {string} imsOrgId - The IMS Org ID.
87
+ * @return {Base} The updated site.
88
+ */
68
89
  self.updateImsOrgId = (imsOrgId) => {
69
90
  if (!hasText(imsOrgId)) {
70
91
  throw new Error('IMS Org ID must be provided');
@@ -81,6 +102,10 @@ const Site = (data = {}) => {
81
102
  return self;
82
103
  };
83
104
 
105
+ /**
106
+ * Sets whether the site is live.
107
+ * @return {Base} The updated site.
108
+ */
84
109
  self.toggleLive = () => {
85
110
  self.state.isLive = !self.state.isLive;
86
111
  return self;
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { isObject } from '@adobe/spacecat-shared-utils';
13
+ import { hasText, isObject } from '@adobe/spacecat-shared-utils';
14
14
 
15
15
  import { AuditDto } from '../../dto/audit.js';
16
16
  import { createAudit } from '../../models/audit.js';
@@ -24,19 +24,29 @@ import { createAudit } from '../../models/audit.js';
24
24
  * @param {Logger} log - The logger.
25
25
  * @param {string} siteId - The ID of the site for which audits are being retrieved.
26
26
  * @param {string} [auditType] - Optional. The type of audits to retrieve.
27
+ * @param {boolean} [ascending] - Optional. Determines if the audits should be sorted
28
+ * ascending. Default is true.
27
29
  * @returns {Promise<Readonly<Audit>[]>} A promise that resolves to an array of audits
28
30
  * for the specified site.
29
31
  */
30
- export const getAuditsForSite = async (dynamoClient, config, log, siteId, auditType) => {
32
+ export const getAuditsForSite = async (
33
+ dynamoClient,
34
+ config,
35
+ log,
36
+ siteId,
37
+ auditType,
38
+ ascending = true,
39
+ ) => {
31
40
  const queryParams = {
32
41
  TableName: config.tableNameAudits,
33
42
  KeyConditionExpression: 'siteId = :siteId',
34
43
  ExpressionAttributeValues: {
35
44
  ':siteId': siteId,
36
45
  },
46
+ ScanIndexForward: ascending, // Sorts ascending if true, descending if false
37
47
  };
38
48
 
39
- if (auditType !== undefined) {
49
+ if (hasText(auditType)) {
40
50
  queryParams.KeyConditionExpression += ' AND begins_with(SK, :auditType)';
41
51
  queryParams.ExpressionAttributeValues[':auditType'] = `${auditType}#`;
42
52
  }