@adobe/spacecat-shared-data-access 1.34.1-config → 1.34.2
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 +3 -3
- package/src/dto/configuration.js +0 -2
- package/src/dto/site.js +3 -0
- package/src/index.d.ts +43 -54
- package/src/models/configuration.js +4 -137
- package/src/models/organization.js +13 -0
- package/src/models/site/audit-config-type.js +60 -0
- package/src/models/site/audit-config.js +85 -0
- package/src/models/site/config.js +30 -56
- package/src/models/site.js +23 -0
- package/src/service/configurations/accessPatterns.js +2 -1
- package/src/service/sites/accessPatterns.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.34.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.34.1...@adobe/spacecat-shared-data-access-v1.34.2) (2024-07-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([#284](https://github.com/adobe/spacecat-shared/issues/284)) ([f4fe169](https://github.com/adobe/spacecat-shared/commit/f4fe1699c432637f1217198ad7f4a1cde6deeb76))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-data-access-v1.34.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.34.0...@adobe/spacecat-shared-data-access-v1.34.1) (2024-06-29)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-data-access",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.2",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Data Access",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@adobe/spacecat-shared-dynamo": "1.2.5",
|
|
33
33
|
"@adobe/spacecat-shared-utils": "1.2.0",
|
|
34
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
35
|
-
"@aws-sdk/lib-dynamodb": "3.
|
|
34
|
+
"@aws-sdk/client-dynamodb": "3.609.0",
|
|
35
|
+
"@aws-sdk/lib-dynamodb": "3.610.0",
|
|
36
36
|
"@types/joi": "17.2.3",
|
|
37
37
|
"joi": "17.13.3",
|
|
38
38
|
"uuid": "10.0.0"
|
package/src/dto/configuration.js
CHANGED
|
@@ -26,7 +26,6 @@ export const ConfigurationDto = {
|
|
|
26
26
|
version: dynamoItem.version,
|
|
27
27
|
queues: dynamoItem.queues,
|
|
28
28
|
jobs: dynamoItem.jobs,
|
|
29
|
-
handlers: dynamoItem.handlers,
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
return createConfiguration(configurationData);
|
|
@@ -42,6 +41,5 @@ export const ConfigurationDto = {
|
|
|
42
41
|
version: configuration.getVersion(),
|
|
43
42
|
queues: configuration.getQueues(),
|
|
44
43
|
jobs: configuration.getJobs(),
|
|
45
|
-
handlers: configuration.getHandlers(),
|
|
46
44
|
}),
|
|
47
45
|
};
|
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
|
import { Config } from '../models/site/config.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -34,6 +35,7 @@ export const SiteDto = {
|
|
|
34
35
|
createdAt: site.getCreatedAt(),
|
|
35
36
|
updatedAt: site.getUpdatedAt(),
|
|
36
37
|
GSI1PK: 'ALL_SITES',
|
|
38
|
+
auditConfig: AuditConfig.toDynamoItem(site.getAuditConfig()),
|
|
37
39
|
config: Config.toDynamoItem(site.getConfig()),
|
|
38
40
|
}),
|
|
39
41
|
|
|
@@ -54,6 +56,7 @@ export const SiteDto = {
|
|
|
54
56
|
isLiveToggledAt: dynamoItem.isLiveToggledAt,
|
|
55
57
|
createdAt: dynamoItem.createdAt,
|
|
56
58
|
updatedAt: dynamoItem.updatedAt,
|
|
59
|
+
auditConfig: dynamoItem.auditConfig,
|
|
57
60
|
config: dynamoItem.config,
|
|
58
61
|
};
|
|
59
62
|
|
package/src/index.d.ts
CHANGED
|
@@ -84,6 +84,18 @@ export interface Audit {
|
|
|
84
84
|
getScores: () => object;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* AuditConfigType defines the structure for specific audit type configurations.
|
|
89
|
+
*/
|
|
90
|
+
export interface AuditConfigType {
|
|
91
|
+
/**
|
|
92
|
+
* Returns true if the audit type is disabled for the site. If an audit type is disabled, no
|
|
93
|
+
* audits of that type will be scheduled for the site.
|
|
94
|
+
* @returns {boolean} True if the audit type is disabled for the site.
|
|
95
|
+
*/
|
|
96
|
+
disabled: () => boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
export interface Config {
|
|
88
100
|
|
|
89
101
|
}
|
|
@@ -92,6 +104,31 @@ export interface FulfillableItems {
|
|
|
92
104
|
items: string[];
|
|
93
105
|
}
|
|
94
106
|
|
|
107
|
+
/**
|
|
108
|
+
* AuditConfig defines the structure for the overall audit configuration of a site.
|
|
109
|
+
*/
|
|
110
|
+
export interface AuditConfig {
|
|
111
|
+
/**
|
|
112
|
+
* Returns true if audits are disabled for the site. If audits are disabled, no audits will be
|
|
113
|
+
* scheduled for the site. Overrides any audit type specific configurations.
|
|
114
|
+
* @returns {boolean} True if audits are disabled for the site.
|
|
115
|
+
*/
|
|
116
|
+
auditsDisabled: () => boolean;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns the audit config for a specific audit type. The audit type is the key.
|
|
120
|
+
* @param {string} auditType The audit type to get the config for.
|
|
121
|
+
* @returns {AuditConfigType} The audit config for the audit type.
|
|
122
|
+
*/
|
|
123
|
+
getAuditTypeConfig: (auditType: string) => AuditConfigType;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Returns the audit configs for all audit types. The keys are the audit types.
|
|
127
|
+
* @returns {object} The audit configs for all audit types.
|
|
128
|
+
*/
|
|
129
|
+
getAuditTypeConfigs: () => object;
|
|
130
|
+
}
|
|
131
|
+
|
|
95
132
|
/**
|
|
96
133
|
* Represents a key event.
|
|
97
134
|
*/
|
|
@@ -185,6 +222,12 @@ export interface Site {
|
|
|
185
222
|
*/
|
|
186
223
|
getUpdatedAt: () => string;
|
|
187
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves the current audit configuration for the site.
|
|
227
|
+
* @returns {AuditConfig} The current audit configuration.
|
|
228
|
+
*/
|
|
229
|
+
getAuditConfig: () => AuditConfig;
|
|
230
|
+
|
|
188
231
|
/**
|
|
189
232
|
* Retrieves the current configuration for the site.
|
|
190
233
|
* @returns {Config} The current configuration.
|
|
@@ -392,60 +435,6 @@ export interface Configuration {
|
|
|
392
435
|
*/
|
|
393
436
|
getJobs: () => Array<object>;
|
|
394
437
|
|
|
395
|
-
/**
|
|
396
|
-
* Retrieves the handlers configuration.
|
|
397
|
-
* @returns {object} The handlers configuration.
|
|
398
|
-
*/
|
|
399
|
-
getHandlers: () => object;
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Retrieves the handler configuration for handler type.
|
|
403
|
-
* @returns {object} The handler type configuration.
|
|
404
|
-
*/
|
|
405
|
-
getHandler: (type) => object;
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Return true if a handler type is enabled for an organization.
|
|
409
|
-
* @param type handler type
|
|
410
|
-
* @param org organization
|
|
411
|
-
*/
|
|
412
|
-
isHandlerEnabledForOrg: (type: string, org: Organization) => boolean;
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Return true if a handler type is enabled for a site.
|
|
416
|
-
* @param type handler type
|
|
417
|
-
* @param site site
|
|
418
|
-
*/
|
|
419
|
-
isHandlerEnabledForSite: (type: string, site: Site) => boolean;
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Enables a handler type for an site.
|
|
423
|
-
* @param type handler type
|
|
424
|
-
* @param site site
|
|
425
|
-
*/
|
|
426
|
-
enableHandlerForSite: (type: string, site: Site) => void;
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Enables a handler type for an organization.
|
|
430
|
-
* @param type handler type
|
|
431
|
-
* @param org organization
|
|
432
|
-
*/
|
|
433
|
-
enableHandlerForOrg: (type: string, org: Organization) => void;
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Disables a handler type for an site.
|
|
437
|
-
* @param type handler type
|
|
438
|
-
* @param site site
|
|
439
|
-
*/
|
|
440
|
-
disableHandlerForSite: (type: string, site: Site) => void;
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Disables a handler type for an organization.
|
|
444
|
-
* @param type handler type
|
|
445
|
-
* @param org organization
|
|
446
|
-
*/
|
|
447
|
-
disableHandlerForOrg: (type:string, org: Organization) => void;
|
|
448
|
-
|
|
449
438
|
}
|
|
450
439
|
|
|
451
440
|
export interface ImportJob {
|
|
@@ -13,151 +13,18 @@
|
|
|
13
13
|
import Joi from 'joi';
|
|
14
14
|
|
|
15
15
|
const Configuration = (data = {}) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
self.
|
|
19
|
-
self.
|
|
20
|
-
self.getQueues = () => self.state.queues;
|
|
21
|
-
self.getHandlers = () => self.state.handlers;
|
|
22
|
-
self.getHandler = (type) => self.state.handlers[type];
|
|
23
|
-
self.addHandler = (type, handlerData) => {
|
|
24
|
-
state.handlers = state.handlers || {};
|
|
25
|
-
state.handlers[type] = { ...handlerData };
|
|
26
|
-
};
|
|
27
|
-
self.isHandlerEnabledForSite = (type, site) => {
|
|
28
|
-
const handler = state.handlers[type];
|
|
29
|
-
if (!handler) return false;
|
|
30
|
-
|
|
31
|
-
const siteId = site.getId();
|
|
32
|
-
const orgId = site.getOrganizationId();
|
|
33
|
-
|
|
34
|
-
if (handler.enabled) {
|
|
35
|
-
return handler.enabled.sites.includes(siteId) || handler.enabled.orgs.includes(orgId);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (handler.disabled) {
|
|
39
|
-
return !((handler.disabled.sites && handler.disabled.sites.includes(siteId))
|
|
40
|
-
|| (handler.disabled.orgs && handler.disabled.orgs.includes(orgId)));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return handler.enabledByDefault;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
self.isHandlerEnabledForOrg = (type, org) => {
|
|
47
|
-
const handler = state.handlers[type];
|
|
48
|
-
if (!handler) return false;
|
|
49
|
-
|
|
50
|
-
const orgId = org.getId();
|
|
51
|
-
|
|
52
|
-
if (handler.enabled) {
|
|
53
|
-
return handler.enabled.orgs.includes(orgId);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (handler.disabled) {
|
|
57
|
-
return !handler.disabled.orgs.includes(orgId);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return handler.enabledByDefault;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const updateHandlerOrgs = (type, orgId, enabled) => {
|
|
64
|
-
const handler = state.handlers[type];
|
|
65
|
-
if (!handler) return;
|
|
66
|
-
|
|
67
|
-
if (enabled) {
|
|
68
|
-
if (handler.enabledByDefault) {
|
|
69
|
-
handler.disabled.orgs = handler.disabled.orgs?.filter((id) => id !== orgId) || [];
|
|
70
|
-
} else {
|
|
71
|
-
handler.enabled = handler.enabled || { orgs: [] };
|
|
72
|
-
handler.enabled.orgs = [...(handler.enabled?.orgs || []), orgId];
|
|
73
|
-
}
|
|
74
|
-
} else if (handler.enabledByDefault) {
|
|
75
|
-
handler.disabled = handler.disabled || { orgs: [] };
|
|
76
|
-
handler.disabled.orgs = [...(handler.disabled?.orgs || []), orgId];
|
|
77
|
-
} else {
|
|
78
|
-
handler.enabled.orgs = handler.enabled.orgs?.filter((id) => id !== orgId) || [];
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const updateHandlerSites = (type, siteId, enabled) => {
|
|
83
|
-
const handler = state.handlers[type];
|
|
84
|
-
if (!handler) return;
|
|
85
|
-
|
|
86
|
-
if (enabled) {
|
|
87
|
-
if (handler.enabledByDefault) {
|
|
88
|
-
handler.disabled.sites = handler.disabled.sites?.filter((id) => id !== siteId) || [];
|
|
89
|
-
} else {
|
|
90
|
-
handler.enabled = handler.enabled || { sites: [] };
|
|
91
|
-
handler.enabled.sites = [...(handler.enabled.sites || []), siteId];
|
|
92
|
-
}
|
|
93
|
-
} else if (handler.enabledByDefault) {
|
|
94
|
-
handler.disabled = handler.disabled || { sites: [] };
|
|
95
|
-
handler.disabled.sites = [...(handler.disabled.sites || []), siteId];
|
|
96
|
-
} else {
|
|
97
|
-
handler.enabled.sites = handler.enabled.sites?.filter((id) => id !== siteId) || [];
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
self.enableHandlerForSite = (type, site) => {
|
|
102
|
-
const siteId = site.getId();
|
|
103
|
-
if (self.isHandlerEnabledForSite(type, site)) return;
|
|
104
|
-
|
|
105
|
-
updateHandlerSites(type, siteId, true);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
self.enableHandlerForOrg = (type, org) => {
|
|
109
|
-
const orgId = org.getId();
|
|
110
|
-
if (self.isHandlerEnabledForOrg(type, org)) return;
|
|
111
|
-
|
|
112
|
-
updateHandlerOrgs(type, orgId, true);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
self.disableHandlerForSite = (type, site) => {
|
|
116
|
-
const siteId = site.getId();
|
|
117
|
-
if (!self.isHandlerEnabledForSite(type, site)) return;
|
|
118
|
-
|
|
119
|
-
updateHandlerSites(type, siteId, false);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
self.disableHandlerForOrg = (type, org) => {
|
|
123
|
-
const orgId = org.getId();
|
|
124
|
-
if (!self.isHandlerEnabledForOrg(type, org)) return;
|
|
125
|
-
|
|
126
|
-
updateHandlerOrgs(type, orgId, false);
|
|
127
|
-
};
|
|
16
|
+
const self = { ...data };
|
|
17
|
+
self.getJobs = () => self.jobs;
|
|
18
|
+
self.getVersion = () => self.version;
|
|
19
|
+
self.getQueues = () => self.queues;
|
|
128
20
|
|
|
129
21
|
return Object.freeze(self);
|
|
130
22
|
};
|
|
131
23
|
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
* @param configuration
|
|
135
|
-
* @returns {any}
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
24
|
export const checkConfiguration = (configuration) => {
|
|
139
25
|
const schema = Joi.object({
|
|
140
26
|
version: Joi.string().required(),
|
|
141
27
|
queues: Joi.object().required(),
|
|
142
|
-
handlers: Joi.object().pattern(Joi.string(), Joi.object(
|
|
143
|
-
{
|
|
144
|
-
enabled: Joi.object({
|
|
145
|
-
sites: Joi.array().items(Joi.string()),
|
|
146
|
-
orgs: Joi.array().items(Joi.string()),
|
|
147
|
-
}),
|
|
148
|
-
disabled: Joi.object({
|
|
149
|
-
sites: Joi.array().items(Joi.string()),
|
|
150
|
-
orgs: Joi.array().items(Joi.string()),
|
|
151
|
-
}),
|
|
152
|
-
enabledByDefault: Joi.boolean().required(),
|
|
153
|
-
dependencies: Joi.array().items(Joi.object(
|
|
154
|
-
{
|
|
155
|
-
handler: Joi.string(),
|
|
156
|
-
actions: Joi.array().items(Joi.string()),
|
|
157
|
-
},
|
|
158
|
-
)),
|
|
159
|
-
},
|
|
160
|
-
)),
|
|
161
28
|
jobs: Joi.array().required(),
|
|
162
29
|
}).unknown(true);
|
|
163
30
|
const { error, value } = schema.validate(configuration);
|
|
@@ -26,11 +26,24 @@ export const DEFAULT_ORGANIZATION_ID = 'default';
|
|
|
26
26
|
const Organization = (data = {}) => {
|
|
27
27
|
const self = Base(data);
|
|
28
28
|
|
|
29
|
+
self.getAuditConfig = () => self.state.config.audits;
|
|
29
30
|
self.getConfig = () => self.state.config;
|
|
30
31
|
self.getName = () => self.state.name;
|
|
31
32
|
self.getImsOrgId = () => self.state.imsOrgId;
|
|
32
33
|
self.getFulfillableItems = () => self.state.fulfillableItems;
|
|
33
34
|
|
|
35
|
+
self.setAllAuditsDisabled = (disabled) => {
|
|
36
|
+
self.state.config.audits.updateAuditsDisabled(disabled);
|
|
37
|
+
self.touch();
|
|
38
|
+
return self;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
self.updateAuditTypeConfig = (type, config) => {
|
|
42
|
+
self.state.config.audits.updateAuditTypeConfig(type, config);
|
|
43
|
+
self.touch();
|
|
44
|
+
return self;
|
|
45
|
+
};
|
|
46
|
+
|
|
34
47
|
/**
|
|
35
48
|
* Updates the IMS Org ID belonging to the organization.
|
|
36
49
|
* @param {string} imsOrgId - The IMS Org ID.
|
|
@@ -0,0 +1,60 @@
|
|
|
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 = {}) => {
|
|
14
|
+
const state = {
|
|
15
|
+
disabled: data.disabled || false,
|
|
16
|
+
excludedURLs: data.excludedURLs || [],
|
|
17
|
+
manualOverwrites: data.manualOverwrites || [],
|
|
18
|
+
fixedURLs: data.fixedURLs || [],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const self = {
|
|
22
|
+
disabled: () => state.disabled,
|
|
23
|
+
getExcludedURLs: () => state.excludedURLs,
|
|
24
|
+
updateExcludedURLs: (excludeURLs) => {
|
|
25
|
+
state.excludedURLs = excludeURLs;
|
|
26
|
+
},
|
|
27
|
+
getManualOverwrites: () => state.manualOverwrites,
|
|
28
|
+
updateManualOverwrites: (manualOverwrites) => {
|
|
29
|
+
state.manualOverwrites = manualOverwrites;
|
|
30
|
+
},
|
|
31
|
+
getFixedURLs: () => state.fixedURLs,
|
|
32
|
+
updateFixedURLs: (fixedURLs) => {
|
|
33
|
+
state.fixedURLs = fixedURLs;
|
|
34
|
+
},
|
|
35
|
+
updateDisabled: (newValue) => {
|
|
36
|
+
state.disabled = newValue;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return Object.freeze(self);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
AuditConfigType.fromDynamoItem = (dynamoItem) => {
|
|
44
|
+
const auditConfigTypeData = {
|
|
45
|
+
disabled: dynamoItem.disabled,
|
|
46
|
+
excludedURLs: dynamoItem.excludedURLs,
|
|
47
|
+
manualOverwrites: dynamoItem.manualOverwrites,
|
|
48
|
+
fixedURLs: dynamoItem.fixedURLs,
|
|
49
|
+
};
|
|
50
|
+
return AuditConfigType(auditConfigTypeData);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
AuditConfigType.toDynamoItem = (auditConfigType) => ({
|
|
54
|
+
disabled: auditConfigType.disabled(),
|
|
55
|
+
excludedURLs: auditConfigType.getExcludedURLs(),
|
|
56
|
+
manualOverwrites: auditConfigType.getManualOverwrites(),
|
|
57
|
+
fixedURLs: auditConfigType.getFixedURLs(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export default AuditConfigType;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
import AuditConfigType from './audit-config-type.js';
|
|
14
|
+
import {
|
|
15
|
+
AUDIT_TYPE_BROKEN_BACKLINKS,
|
|
16
|
+
AUDIT_TYPE_EXPERIMENTATION_ESS_DAILY,
|
|
17
|
+
AUDIT_TYPE_EXPERIMENTATION_ESS_MONTHLY,
|
|
18
|
+
AUDIT_TYPE_ORGANIC_KEYWORDS,
|
|
19
|
+
AUDIT_TYPE_ORGANIC_TRAFFIC,
|
|
20
|
+
} from '../audit.js';
|
|
21
|
+
|
|
22
|
+
const AUDIT_TYPE_DISABLED_DEFAULTS = {
|
|
23
|
+
[AUDIT_TYPE_BROKEN_BACKLINKS]: true,
|
|
24
|
+
[AUDIT_TYPE_EXPERIMENTATION_ESS_DAILY]: true,
|
|
25
|
+
[AUDIT_TYPE_EXPERIMENTATION_ESS_MONTHLY]: true,
|
|
26
|
+
[AUDIT_TYPE_ORGANIC_KEYWORDS]: true,
|
|
27
|
+
[AUDIT_TYPE_ORGANIC_TRAFFIC]: true,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) {
|
|
31
|
+
if (!auditTypeConfigs || Object.keys(auditTypeConfigs).length === 0) {
|
|
32
|
+
return {
|
|
33
|
+
[AUDIT_TYPE_BROKEN_BACKLINKS]: AuditConfigType({ disabled: true }),
|
|
34
|
+
[AUDIT_TYPE_EXPERIMENTATION_ESS_DAILY]: AuditConfigType({ disabled: true }),
|
|
35
|
+
[AUDIT_TYPE_EXPERIMENTATION_ESS_MONTHLY]: AuditConfigType({ disabled: true }),
|
|
36
|
+
[AUDIT_TYPE_ORGANIC_KEYWORDS]: AuditConfigType({ disabled: true }),
|
|
37
|
+
[AUDIT_TYPE_ORGANIC_TRAFFIC]: AuditConfigType({ disabled: true }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return Object.entries(auditTypeConfigs || {}).reduce((acc, [key, value]) => {
|
|
41
|
+
const disabled = value.disabled !== undefined
|
|
42
|
+
? value.disabled : (AUDIT_TYPE_DISABLED_DEFAULTS[key] || auditsDisabled || false);
|
|
43
|
+
acc[key] = AuditConfigType(
|
|
44
|
+
{
|
|
45
|
+
...value,
|
|
46
|
+
disabled,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const AuditConfig = (data = {}) => {
|
|
54
|
+
const state = {
|
|
55
|
+
auditsDisabled: data.auditsDisabled || false,
|
|
56
|
+
auditTypeConfigs: getAuditTypeConfigs(data.auditTypeConfigs, data.auditsDisabled),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const self = {
|
|
60
|
+
auditsDisabled: () => state.auditsDisabled,
|
|
61
|
+
getAuditTypeConfigs: () => state.auditTypeConfigs,
|
|
62
|
+
getAuditTypeConfig: (type) => state.auditTypeConfigs[type],
|
|
63
|
+
updateAuditsDisabled: (newValue) => {
|
|
64
|
+
state.auditsDisabled = newValue;
|
|
65
|
+
},
|
|
66
|
+
updateAuditTypeConfig: (type, config) => {
|
|
67
|
+
state.auditTypeConfigs[type] = AuditConfigType(config);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return Object.freeze(self);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
AuditConfig.fromDynamoItem = (dynamoItem) => AuditConfig(dynamoItem);
|
|
75
|
+
|
|
76
|
+
AuditConfig.toDynamoItem = (auditConfig) => ({
|
|
77
|
+
auditsDisabled: auditConfig.auditsDisabled(),
|
|
78
|
+
auditTypeConfigs: Object.entries(auditConfig.getAuditTypeConfigs())
|
|
79
|
+
.reduce((acc, [key, value]) => {
|
|
80
|
+
acc[key] = AuditConfigType.toDynamoItem(value);
|
|
81
|
+
return acc;
|
|
82
|
+
}, {}),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export default AuditConfig;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import Joi from 'joi';
|
|
14
|
+
import AuditConfig from './audit-config.js';
|
|
14
15
|
|
|
15
16
|
export const configSchema = Joi.object({
|
|
16
17
|
slack: Joi.object({
|
|
@@ -18,24 +19,35 @@ export const configSchema = Joi.object({
|
|
|
18
19
|
channel: Joi.string(),
|
|
19
20
|
invitedUserCount: Joi.number().integer().min(0),
|
|
20
21
|
}),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
alerts: Joi.array().items(Joi.object({
|
|
23
|
+
type: Joi.string().required(),
|
|
24
|
+
byOrg: Joi.boolean(),
|
|
25
|
+
mentions: Joi.array().items(Joi.object({ slack: Joi.array().items(Joi.string()) })),
|
|
26
|
+
}).unknown(true)),
|
|
27
|
+
audits: Joi.object({
|
|
28
|
+
auditsDisabled: Joi.boolean().optional(),
|
|
29
|
+
auditTypeConfigs: Joi.object().pattern(
|
|
30
|
+
Joi.string(),
|
|
31
|
+
Joi.object({
|
|
32
|
+
disabled: Joi.boolean().optional(),
|
|
33
|
+
excludedURLs: Joi.array().items(Joi.string()).optional(),
|
|
34
|
+
manualOverwrites: Joi.array().items(Joi.object({
|
|
35
|
+
brokenTargetURL: Joi.string().optional(),
|
|
36
|
+
targetURL: Joi.string().optional(),
|
|
37
|
+
})).optional(),
|
|
38
|
+
fixedURLs: Joi.array().items(Joi.object({
|
|
39
|
+
brokenTargetURL: Joi.string().optional(),
|
|
40
|
+
targetURL: Joi.string().optional(),
|
|
41
|
+
})).optional(),
|
|
42
|
+
}).unknown(true),
|
|
43
|
+
).unknown(true),
|
|
44
|
+
}).unknown(true),
|
|
33
45
|
}).unknown(true);
|
|
34
46
|
|
|
35
47
|
export const DEFAULT_CONFIG = {
|
|
36
48
|
slack: {},
|
|
37
|
-
|
|
38
|
-
},
|
|
49
|
+
alerts: [],
|
|
50
|
+
audits: {},
|
|
39
51
|
};
|
|
40
52
|
|
|
41
53
|
// Function to validate incoming configuration
|
|
@@ -51,49 +63,11 @@ function validateConfiguration(config) {
|
|
|
51
63
|
|
|
52
64
|
export const Config = (data = {}) => {
|
|
53
65
|
const validConfig = validateConfiguration(data);
|
|
66
|
+
validConfig.audits = AuditConfig(validConfig.audits);
|
|
54
67
|
|
|
55
68
|
const state = { ...validConfig };
|
|
56
|
-
const self = { state };
|
|
57
|
-
self.getSlackConfig = () => state.slack;
|
|
58
|
-
self.getSlackMentions = (type) => state?.handlers[type]?.mentions?.slack;
|
|
59
|
-
self.getHandlerConfig = (type) => state?.handlers[type];
|
|
60
|
-
self.getHandlers = () => state.handlers;
|
|
61
|
-
self.getExcludedURLs = (type) => state?.handlers[type]?.excludedURLs;
|
|
62
|
-
self.getManualOverrides = (type) => state?.handlers[type]?.manualOverwrites;
|
|
63
|
-
self.getFixedURLs = (type) => state?.handlers[type]?.fixedURLs;
|
|
64
69
|
|
|
65
|
-
self
|
|
66
|
-
state.slack = {
|
|
67
|
-
channel,
|
|
68
|
-
workspace,
|
|
69
|
-
invitedUserCount,
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
self.updateSlackMentions = (type, mentions) => {
|
|
74
|
-
state.handlers = state.handlers || {};
|
|
75
|
-
state.handlers[type] = state.handlers[type] || {};
|
|
76
|
-
state.handlers[type].mentions = state.handlers[type].mentions || {};
|
|
77
|
-
state.handlers[type].mentions.slack = mentions;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
self.updateExcludeURLs = (type, excludedURLs) => {
|
|
81
|
-
state.handlers = state.handlers || {};
|
|
82
|
-
state.handlers[type] = state.handlers[type] || {};
|
|
83
|
-
state.handlers[type].excludedURLs = excludedURLs;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
self.updateManualOverrides = (type, manualOverwrites) => {
|
|
87
|
-
state.handlers = state.handlers || {};
|
|
88
|
-
state.handlers[type] = state.handlers[type] || {};
|
|
89
|
-
state.handlers[type].manualOverwrites = manualOverwrites;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
self.updateFixedURLs = (type, fixedURLs) => {
|
|
93
|
-
state.handlers = state.handlers || {};
|
|
94
|
-
state.handlers[type] = state.handlers[type] || {};
|
|
95
|
-
state.handlers[type].fixedURLs = fixedURLs;
|
|
96
|
-
};
|
|
70
|
+
const self = { ...state };
|
|
97
71
|
|
|
98
72
|
return Object.freeze(self);
|
|
99
73
|
};
|
|
@@ -101,6 +75,6 @@ export const Config = (data = {}) => {
|
|
|
101
75
|
Config.fromDynamoItem = (dynamoItem) => Config(dynamoItem);
|
|
102
76
|
|
|
103
77
|
Config.toDynamoItem = (config) => ({
|
|
104
|
-
|
|
105
|
-
|
|
78
|
+
...config,
|
|
79
|
+
audits: AuditConfig.toDynamoItem(config.audits),
|
|
106
80
|
});
|
package/src/models/site.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { hasText, isObject, isValidUrl } from '@adobe/spacecat-shared-utils';
|
|
14
14
|
|
|
15
15
|
import { Base } from './base.js';
|
|
16
|
+
import AuditConfig from './site/audit-config.js';
|
|
16
17
|
import { Config, DEFAULT_CONFIG } from './site/config.js';
|
|
17
18
|
import { DEFAULT_ORGANIZATION_ID } from './organization.js';
|
|
18
19
|
|
|
@@ -33,6 +34,7 @@ export const DEFAULT_DELIVERY_TYPE = DELIVERY_TYPES.AEM_EDGE;
|
|
|
33
34
|
const Site = (data = {}) => {
|
|
34
35
|
const self = Base(data);
|
|
35
36
|
|
|
37
|
+
self.getAuditConfig = () => self.state.auditConfig;
|
|
36
38
|
self.getAudits = () => self.state.audits;
|
|
37
39
|
self.getBaseURL = () => self.state.baseURL;
|
|
38
40
|
self.getConfig = () => self.state.config;
|
|
@@ -80,6 +82,18 @@ const Site = (data = {}) => {
|
|
|
80
82
|
return self;
|
|
81
83
|
}; */
|
|
82
84
|
|
|
85
|
+
self.setAllAuditsDisabled = (disabled) => {
|
|
86
|
+
self.state.auditConfig.updateAuditsDisabled(disabled);
|
|
87
|
+
self.touch();
|
|
88
|
+
return self;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
self.updateAuditTypeConfig = (type, config) => {
|
|
92
|
+
self.state.auditConfig.updateAuditTypeConfig(type, config);
|
|
93
|
+
self.touch();
|
|
94
|
+
return self;
|
|
95
|
+
};
|
|
96
|
+
|
|
83
97
|
/**
|
|
84
98
|
* Updates the site config.
|
|
85
99
|
* @param {string} config - The Site config.
|
|
@@ -208,6 +222,15 @@ export const createSite = (data) => {
|
|
|
208
222
|
newState.audits = [];
|
|
209
223
|
}
|
|
210
224
|
|
|
225
|
+
if (!isObject(newState.auditConfig)) {
|
|
226
|
+
newState.auditConfig = {
|
|
227
|
+
auditsDisabled: false,
|
|
228
|
+
auditTypeConfigs: {},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
newState.auditConfig = AuditConfig(newState.auditConfig);
|
|
233
|
+
|
|
211
234
|
if (!isObject(newState.config)) {
|
|
212
235
|
newState.config = { ...DEFAULT_CONFIG };
|
|
213
236
|
}
|
|
@@ -110,7 +110,8 @@ export const updateConfiguration = async (
|
|
|
110
110
|
const newConfigurationData = { ...configurationData };
|
|
111
111
|
const latestConfiguration = await getConfiguration(dynamoClient, config);
|
|
112
112
|
|
|
113
|
-
newConfigurationData.version = incrementVersion(latestConfiguration?.
|
|
113
|
+
newConfigurationData.version = incrementVersion(latestConfiguration?.version);
|
|
114
|
+
newConfigurationData.PK = config.pkAllConfigurations;
|
|
114
115
|
|
|
115
116
|
const newConfiguration = createConfiguration(newConfigurationData);
|
|
116
117
|
|