@adobe/spacecat-shared-data-access 1.2.7 → 1.3.1

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.3.1](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.3.0...@adobe/spacecat-shared-data-access-v1.3.1) (2023-12-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * type def / jsdoc ([#61](https://github.com/adobe-rnd/spacecat-shared/issues/61)) ([078f9e6](https://github.com/adobe-rnd/spacecat-shared/commit/078f9e6855d3f475f3a746561758aaefb5cb3c79))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.3.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.7...@adobe/spacecat-shared-data-access-v1.3.0) (2023-12-16)
9
+
10
+
11
+ ### Features
12
+
13
+ * add audit config ([#59](https://github.com/adobe-rnd/spacecat-shared/issues/59)) ([f851862](https://github.com/adobe-rnd/spacecat-shared/commit/f8518623a8b8e4e337b3c44a16b65724a953596a))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.2.7](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.6...@adobe/spacecat-shared-data-access-v1.2.7) (2023-12-11)
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.7",
3
+ "version": "1.3.1",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/dto/site.js CHANGED
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import { createSite } from '../models/site.js';
14
+ import AuditConfig from '../models/site/audit-config.js';
14
15
 
15
16
  /**
16
17
  * Data transfer object for Site.
@@ -30,6 +31,7 @@ export const SiteDto = {
30
31
  createdAt: site.getCreatedAt(),
31
32
  updatedAt: site.getUpdatedAt(),
32
33
  GSI1PK: 'ALL_SITES',
34
+ auditConfig: AuditConfig.toDynamoItem(site.getAuditConfig()),
33
35
  }),
34
36
 
35
37
  /**
@@ -46,6 +48,7 @@ export const SiteDto = {
46
48
  isLive: dynamoItem.isLive,
47
49
  createdAt: dynamoItem.createdAt,
48
50
  updatedAt: dynamoItem.updatedAt,
51
+ auditConfig: dynamoItem.auditConfig,
49
52
  };
50
53
 
51
54
  return createSite(siteData);
package/src/index.d.ts CHANGED
@@ -20,9 +20,45 @@ export interface Audit {
20
20
  getExpiresAt: () => Date;
21
21
  getFullAuditRef: () => string;
22
22
  isLive: () => boolean;
23
+ isError: () => boolean;
23
24
  getScores: () => object;
24
25
  }
25
26
 
27
+ /**
28
+ * AuditConfigType defines the structure for specific audit type configurations
29
+ */
30
+ export interface AuditConfigType {
31
+ /**
32
+ * Returns true if the audit type is disabled for the site. If an audit type is disabled, no
33
+ * audits of that type will be scheduled for the site.
34
+ * @returns True if the audit type is disabled for the site
35
+ */
36
+ disabled(): boolean;
37
+ }
38
+
39
+ /**
40
+ * AuditConfig defines the structure for the overall audit configuration of a site
41
+ */
42
+ export interface AuditConfig {
43
+ /**
44
+ * Returns true if audits are disabled for the site. If audits are disabled, no audits will be
45
+ * scheduled for the site. Overrides any audit type specific configurations.
46
+ * @returns True if audits are disabled for the site
47
+ */
48
+ auditsDisabled: () => boolean;
49
+ /**
50
+ * Returns the audit config for a specific audit type. The audit type is the key.
51
+ * @param auditType The audit type to get the config for
52
+ * @returns The audit config for the audit type
53
+ */
54
+ getAuditTypeConfig: (auditType: string) => AuditConfigType;
55
+ /**
56
+ * Returns the audit configs for all audit types. The keys are the audit types.
57
+ * @returns The audit configs for all audit types
58
+ */
59
+ getAuditTypeConfigs: () => object;
60
+ }
61
+
26
62
  export interface Site {
27
63
  getId: () => string;
28
64
  getBaseURL: () => string;
@@ -30,6 +66,7 @@ export interface Site {
30
66
  getImsOrgId: () => string;
31
67
  getCreatedAt: () => string;
32
68
  getUpdatedAt: () => string;
69
+ getAuditConfig: () => AuditConfig;
33
70
  getAudits: () => Audit[];
34
71
  isLive: () => boolean;
35
72
  setAudits: (audits: Audit[]) => Site;
@@ -61,6 +61,7 @@ const Audit = (data = {}) => {
61
61
  self.getExpiresAt = () => self.state.expiresAt;
62
62
  self.getFullAuditRef = () => self.state.fullAuditRef;
63
63
  self.isLive = () => self.state.isLive;
64
+ self.isError = () => hasText(self.getAuditResult().runtimeError?.code);
64
65
  self.getScores = () => self.getAuditResult().scores;
65
66
 
66
67
  return Object.freeze(self);
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright 2023 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ const AuditConfigType = (data = {}, allAuditsDisabled = false) => ({
14
+ disabled: () => allAuditsDisabled || data.disabled || false,
15
+ });
16
+
17
+ AuditConfigType.fromDynamoItem = (dynamoItem) => {
18
+ const auditConfigTypeData = {
19
+ disabled: dynamoItem.disabled,
20
+ };
21
+ return AuditConfigType(auditConfigTypeData);
22
+ };
23
+
24
+ AuditConfigType.toDynamoItem = (auditConfigType) => ({
25
+ disabled: auditConfigType.disabled(),
26
+ });
27
+
28
+ export default AuditConfigType;
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright 2023 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import AuditConfigType from './audit-config-type.js';
13
+
14
+ /**
15
+ * Initializes the audit type configs. If auditsDisabled is true, all audit types will be disabled.
16
+ * @param {object} auditTypeConfigs - Object containing audit type configs.
17
+ * @param {boolean} auditsDisabled - Flag indicating if all audits are disabled.
18
+ * @return {object} Object containing audit type configs.
19
+ */
20
+ function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) {
21
+ return Object.entries(auditTypeConfigs || {}).reduce((acc, [key, value]) => {
22
+ acc[key] = AuditConfigType(value, auditsDisabled);
23
+ return acc;
24
+ }, {});
25
+ }
26
+
27
+ const AuditConfig = (data = {}) => {
28
+ const auditTypeConfigs = getAuditTypeConfigs(data.auditTypeConfigs, data.auditsDisabled);
29
+ return {
30
+ auditsDisabled: () => data.auditsDisabled || false,
31
+ getAuditTypeConfigs: () => auditTypeConfigs,
32
+ getAuditTypeConfig: (type) => auditTypeConfigs[type],
33
+ };
34
+ };
35
+
36
+ AuditConfig.fromDynamoItem = (dynamoItem) => AuditConfig(dynamoItem);
37
+
38
+ AuditConfig.toDynamoItem = (auditConfig) => ({
39
+ auditsDisabled: auditConfig.auditsDisabled(),
40
+ auditTypeConfigs: Object.entries(auditConfig.getAuditTypeConfigs())
41
+ .reduce((acc, [key, value]) => {
42
+ acc[key] = AuditConfigType.toDynamoItem(value);
43
+ return acc;
44
+ }, {}),
45
+ });
46
+
47
+ export default AuditConfig;
@@ -10,8 +10,10 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { hasText, isValidUrl } from '@adobe/spacecat-shared-utils';
13
+ import { hasText, isObject, isValidUrl } from '@adobe/spacecat-shared-utils';
14
+
14
15
  import { Base } from './base.js';
16
+ import AuditConfig from './site/audit-config.js';
15
17
 
16
18
  /**
17
19
  * Creates a new Site.
@@ -22,6 +24,7 @@ import { Base } from './base.js';
22
24
  const Site = (data = {}) => {
23
25
  const self = Base(data);
24
26
 
27
+ self.getAuditConfig = () => self.state.auditConfig;
25
28
  self.getAudits = () => self.state.audits;
26
29
  self.getBaseURL = () => self.state.baseURL;
27
30
  self.getGitHubURL = () => self.state.gitHubURL;
@@ -135,5 +138,14 @@ export const createSite = (data) => {
135
138
  newState.audits = [];
136
139
  }
137
140
 
141
+ if (!isObject(newState.auditConfig)) {
142
+ newState.auditConfig = {
143
+ auditsDisabled: false,
144
+ auditTypeConfigs: {},
145
+ };
146
+ }
147
+
148
+ newState.auditConfig = AuditConfig(newState.auditConfig);
149
+
138
150
  return Site(newState);
139
151
  };