@adobe/spacecat-shared-data-access 1.2.7 → 1.3.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 +7 -0
- package/package.json +1 -1
- package/src/dto/site.js +3 -0
- package/src/index.d.ts +13 -0
- package/src/models/audit.js +1 -0
- package/src/models/site/audit-config-type.js +28 -0
- package/src/models/site/audit-config.js +41 -0
- package/src/models/site.js +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@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)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add audit config ([#59](https://github.com/adobe-rnd/spacecat-shared/issues/59)) ([f851862](https://github.com/adobe-rnd/spacecat-shared/commit/f8518623a8b8e4e337b3c44a16b65724a953596a))
|
|
7
|
+
|
|
1
8
|
# [@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
9
|
|
|
3
10
|
|
package/package.json
CHANGED
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,21 @@ 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
|
+
// AuditConfigType defines the structure for specific audit type configurations
|
|
28
|
+
export interface AuditConfigType {
|
|
29
|
+
disabled(): boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// AuditConfig defines the structure for the overall audit configuration of a site
|
|
33
|
+
export interface AuditConfig {
|
|
34
|
+
auditsDisabled: () => boolean;
|
|
35
|
+
getAuditConfigForType: (auditType: string) => AuditConfigType;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
export interface Site {
|
|
27
39
|
getId: () => string;
|
|
28
40
|
getBaseURL: () => string;
|
|
@@ -30,6 +42,7 @@ export interface Site {
|
|
|
30
42
|
getImsOrgId: () => string;
|
|
31
43
|
getCreatedAt: () => string;
|
|
32
44
|
getUpdatedAt: () => string;
|
|
45
|
+
getAuditConfig: () => AuditConfig;
|
|
33
46
|
getAudits: () => Audit[];
|
|
34
47
|
isLive: () => boolean;
|
|
35
48
|
setAudits: (audits: Audit[]) => Site;
|
package/src/models/audit.js
CHANGED
|
@@ -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,41 @@
|
|
|
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
|
+
function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) {
|
|
15
|
+
return Object.entries(auditTypeConfigs || {}).reduce((acc, [key, value]) => {
|
|
16
|
+
acc[key] = AuditConfigType(value, auditsDisabled);
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const AuditConfig = (data = {}) => {
|
|
22
|
+
const auditTypeConfigs = getAuditTypeConfigs(data.auditTypeConfigs, data.auditsDisabled);
|
|
23
|
+
return {
|
|
24
|
+
auditsDisabled: () => data.auditsDisabled || false,
|
|
25
|
+
getAuditTypeConfigs: () => auditTypeConfigs,
|
|
26
|
+
getAuditTypeConfig: (type) => auditTypeConfigs[type],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
AuditConfig.fromDynamoItem = (dynamoItem) => AuditConfig(dynamoItem);
|
|
31
|
+
|
|
32
|
+
AuditConfig.toDynamoItem = (auditConfig) => ({
|
|
33
|
+
auditsDisabled: auditConfig.auditsDisabled(),
|
|
34
|
+
auditTypeConfigs: Object.entries(auditConfig.getAuditTypeConfigs())
|
|
35
|
+
.reduce((acc, [key, value]) => {
|
|
36
|
+
acc[key] = AuditConfigType.toDynamoItem(value);
|
|
37
|
+
return acc;
|
|
38
|
+
}, {}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default AuditConfig;
|
package/src/models/site.js
CHANGED
|
@@ -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
|
};
|