@adobe/spacecat-shared-data-access 1.33.1 → 1.34.1-config
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 +14 -0
- package/package.json +3 -3
- package/src/dto/configuration.js +2 -0
- package/src/dto/site-candidate.js +2 -0
- package/src/dto/site.js +2 -3
- package/src/index.d.ts +54 -43
- package/src/models/configuration.js +137 -4
- package/src/models/organization.js +0 -13
- package/src/models/site/config.js +56 -30
- package/src/models/site-candidate.js +16 -1
- package/src/models/site.js +26 -23
- package/src/service/configurations/accessPatterns.js +1 -2
- package/src/service/sites/accessPatterns.js +0 -1
- package/src/models/site/audit-config-type.js +0 -60
- package/src/models/site/audit-config.js +0 -85
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@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
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([#279](https://github.com/adobe/spacecat-shared/issues/279)) ([4710607](https://github.com/adobe/spacecat-shared/commit/471060797fac55649ff0c0ea24129bdd421d46b2))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v1.34.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.33.1...@adobe/spacecat-shared-data-access-v1.34.0) (2024-06-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add helix config to site/candidates ([#277](https://github.com/adobe/spacecat-shared/issues/277)) ([5ed489d](https://github.com/adobe/spacecat-shared/commit/5ed489dc84cb594689092e1f0019dd83d3647039))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v1.33.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.33.0...@adobe/spacecat-shared-data-access-v1.33.1) (2024-06-27)
|
|
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.
|
|
3
|
+
"version": "1.34.1-config",
|
|
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.606.0",
|
|
35
|
+
"@aws-sdk/lib-dynamodb": "3.606.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,6 +26,7 @@ export const ConfigurationDto = {
|
|
|
26
26
|
version: dynamoItem.version,
|
|
27
27
|
queues: dynamoItem.queues,
|
|
28
28
|
jobs: dynamoItem.jobs,
|
|
29
|
+
handlers: dynamoItem.handlers,
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
return createConfiguration(configurationData);
|
|
@@ -41,5 +42,6 @@ export const ConfigurationDto = {
|
|
|
41
42
|
version: configuration.getVersion(),
|
|
42
43
|
queues: configuration.getQueues(),
|
|
43
44
|
jobs: configuration.getJobs(),
|
|
45
|
+
handlers: configuration.getHandlers(),
|
|
44
46
|
}),
|
|
45
47
|
};
|
|
@@ -23,6 +23,7 @@ export const SiteCandidateDto = {
|
|
|
23
23
|
*/
|
|
24
24
|
toDynamoItem: (siteCandidate) => ({
|
|
25
25
|
baseURL: siteCandidate.getBaseURL(),
|
|
26
|
+
hlxConfig: siteCandidate.getHlxConfig(),
|
|
26
27
|
siteId: siteCandidate.getSiteId(),
|
|
27
28
|
source: siteCandidate.getSource(),
|
|
28
29
|
status: siteCandidate.getStatus(),
|
|
@@ -39,6 +40,7 @@ export const SiteCandidateDto = {
|
|
|
39
40
|
fromDynamoItem: (dynamoItem) => {
|
|
40
41
|
const siteCandidateData = {
|
|
41
42
|
baseURL: dynamoItem.baseURL,
|
|
43
|
+
hlxConfig: dynamoItem.hlxConfig,
|
|
42
44
|
siteId: dynamoItem.siteId,
|
|
43
45
|
source: dynamoItem.source,
|
|
44
46
|
status: dynamoItem.status,
|
package/src/dto/site.js
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { createSite } from '../models/site.js';
|
|
14
|
-
import AuditConfig from '../models/site/audit-config.js';
|
|
15
14
|
import { Config } from '../models/site/config.js';
|
|
16
15
|
|
|
17
16
|
/**
|
|
@@ -28,13 +27,13 @@ export const SiteDto = {
|
|
|
28
27
|
baseURL: site.getBaseURL(),
|
|
29
28
|
deliveryType: site.getDeliveryType(),
|
|
30
29
|
gitHubURL: site.getGitHubURL() || '',
|
|
30
|
+
hlxConfig: site.getHlxConfig(),
|
|
31
31
|
organizationId: site.getOrganizationId() || '',
|
|
32
32
|
isLive: site.isLive(),
|
|
33
33
|
isLiveToggledAt: site.getIsLiveToggledAt(),
|
|
34
34
|
createdAt: site.getCreatedAt(),
|
|
35
35
|
updatedAt: site.getUpdatedAt(),
|
|
36
36
|
GSI1PK: 'ALL_SITES',
|
|
37
|
-
auditConfig: AuditConfig.toDynamoItem(site.getAuditConfig()),
|
|
38
37
|
config: Config.toDynamoItem(site.getConfig()),
|
|
39
38
|
}),
|
|
40
39
|
|
|
@@ -49,12 +48,12 @@ export const SiteDto = {
|
|
|
49
48
|
baseURL: dynamoItem.baseURL,
|
|
50
49
|
deliveryType: dynamoItem.deliveryType,
|
|
51
50
|
gitHubURL: dynamoItem.gitHubURL,
|
|
51
|
+
hlxConfig: dynamoItem.hlxConfig,
|
|
52
52
|
organizationId: dynamoItem.organizationId,
|
|
53
53
|
isLive: dynamoItem.isLive,
|
|
54
54
|
isLiveToggledAt: dynamoItem.isLiveToggledAt,
|
|
55
55
|
createdAt: dynamoItem.createdAt,
|
|
56
56
|
updatedAt: dynamoItem.updatedAt,
|
|
57
|
-
auditConfig: dynamoItem.auditConfig,
|
|
58
57
|
config: dynamoItem.config,
|
|
59
58
|
};
|
|
60
59
|
|
package/src/index.d.ts
CHANGED
|
@@ -84,18 +84,6 @@ 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
|
-
|
|
99
87
|
export interface Config {
|
|
100
88
|
|
|
101
89
|
}
|
|
@@ -104,31 +92,6 @@ export interface FulfillableItems {
|
|
|
104
92
|
items: string[];
|
|
105
93
|
}
|
|
106
94
|
|
|
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
|
-
|
|
132
95
|
/**
|
|
133
96
|
* Represents a key event.
|
|
134
97
|
*/
|
|
@@ -222,12 +185,6 @@ export interface Site {
|
|
|
222
185
|
*/
|
|
223
186
|
getUpdatedAt: () => string;
|
|
224
187
|
|
|
225
|
-
/**
|
|
226
|
-
* Retrieves the current audit configuration for the site.
|
|
227
|
-
* @returns {AuditConfig} The current audit configuration.
|
|
228
|
-
*/
|
|
229
|
-
getAuditConfig: () => AuditConfig;
|
|
230
|
-
|
|
231
188
|
/**
|
|
232
189
|
* Retrieves the current configuration for the site.
|
|
233
190
|
* @returns {Config} The current configuration.
|
|
@@ -435,6 +392,60 @@ export interface Configuration {
|
|
|
435
392
|
*/
|
|
436
393
|
getJobs: () => Array<object>;
|
|
437
394
|
|
|
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
|
+
|
|
438
449
|
}
|
|
439
450
|
|
|
440
451
|
export interface ImportJob {
|
|
@@ -13,18 +13,151 @@
|
|
|
13
13
|
import Joi from 'joi';
|
|
14
14
|
|
|
15
15
|
const Configuration = (data = {}) => {
|
|
16
|
-
const
|
|
17
|
-
self
|
|
18
|
-
self.
|
|
19
|
-
self.
|
|
16
|
+
const state = { ...data };
|
|
17
|
+
const self = { state };
|
|
18
|
+
self.getJobs = () => self.state.jobs;
|
|
19
|
+
self.getVersion = () => self.state.version;
|
|
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
|
+
};
|
|
20
128
|
|
|
21
129
|
return Object.freeze(self);
|
|
22
130
|
};
|
|
23
131
|
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
* @param configuration
|
|
135
|
+
* @returns {any}
|
|
136
|
+
*/
|
|
137
|
+
|
|
24
138
|
export const checkConfiguration = (configuration) => {
|
|
25
139
|
const schema = Joi.object({
|
|
26
140
|
version: Joi.string().required(),
|
|
27
141
|
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
|
+
)),
|
|
28
161
|
jobs: Joi.array().required(),
|
|
29
162
|
}).unknown(true);
|
|
30
163
|
const { error, value } = schema.validate(configuration);
|
|
@@ -26,24 +26,11 @@ 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;
|
|
30
29
|
self.getConfig = () => self.state.config;
|
|
31
30
|
self.getName = () => self.state.name;
|
|
32
31
|
self.getImsOrgId = () => self.state.imsOrgId;
|
|
33
32
|
self.getFulfillableItems = () => self.state.fulfillableItems;
|
|
34
33
|
|
|
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
|
-
|
|
47
34
|
/**
|
|
48
35
|
* Updates the IMS Org ID belonging to the organization.
|
|
49
36
|
* @param {string} imsOrgId - The IMS Org ID.
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import Joi from 'joi';
|
|
14
|
-
import AuditConfig from './audit-config.js';
|
|
15
14
|
|
|
16
15
|
export const configSchema = Joi.object({
|
|
17
16
|
slack: Joi.object({
|
|
@@ -19,35 +18,24 @@ export const configSchema = Joi.object({
|
|
|
19
18
|
channel: Joi.string(),
|
|
20
19
|
invitedUserCount: Joi.number().integer().min(0),
|
|
21
20
|
}),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Joi.string(),
|
|
31
|
-
Joi.
|
|
32
|
-
|
|
33
|
-
|
|
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),
|
|
21
|
+
handlers: Joi.object().pattern(Joi.string(), Joi.object({
|
|
22
|
+
mentions: Joi.object().pattern(Joi.string(), Joi.array().items(Joi.string())),
|
|
23
|
+
excludedURLs: Joi.array().items(Joi.string()),
|
|
24
|
+
manualOverwrites: Joi.array().items(Joi.object({
|
|
25
|
+
brokenTargetURL: Joi.string().optional(),
|
|
26
|
+
targetURL: Joi.string().optional(),
|
|
27
|
+
})).optional(),
|
|
28
|
+
fixedURLs: Joi.array().items(Joi.object({
|
|
29
|
+
brokenTargetURL: Joi.string().optional(),
|
|
30
|
+
targetURL: Joi.string().optional(),
|
|
31
|
+
})).optional(),
|
|
32
|
+
}).unknown(true)).unknown(true),
|
|
45
33
|
}).unknown(true);
|
|
46
34
|
|
|
47
35
|
export const DEFAULT_CONFIG = {
|
|
48
36
|
slack: {},
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
handlers: {
|
|
38
|
+
},
|
|
51
39
|
};
|
|
52
40
|
|
|
53
41
|
// Function to validate incoming configuration
|
|
@@ -63,11 +51,49 @@ function validateConfiguration(config) {
|
|
|
63
51
|
|
|
64
52
|
export const Config = (data = {}) => {
|
|
65
53
|
const validConfig = validateConfiguration(data);
|
|
66
|
-
validConfig.audits = AuditConfig(validConfig.audits);
|
|
67
54
|
|
|
68
55
|
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;
|
|
69
64
|
|
|
70
|
-
|
|
65
|
+
self.updateSlackConfig = (channel, workspace, invitedUserCount) => {
|
|
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
|
+
};
|
|
71
97
|
|
|
72
98
|
return Object.freeze(self);
|
|
73
99
|
};
|
|
@@ -75,6 +101,6 @@ export const Config = (data = {}) => {
|
|
|
75
101
|
Config.fromDynamoItem = (dynamoItem) => Config(dynamoItem);
|
|
76
102
|
|
|
77
103
|
Config.toDynamoItem = (config) => ({
|
|
78
|
-
|
|
79
|
-
|
|
104
|
+
slack: config.getSlackConfig(),
|
|
105
|
+
handlers: config.getHandlers(),
|
|
80
106
|
});
|
|
@@ -10,7 +10,7 @@
|
|
|
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
15
|
import { Base } from './base.js';
|
|
16
16
|
|
|
@@ -43,6 +43,7 @@ const SiteCandidate = (data = {}) => {
|
|
|
43
43
|
delete self.state.id; // no id property used in SiteCandidate modal
|
|
44
44
|
|
|
45
45
|
self.getBaseURL = () => self.state.baseURL;
|
|
46
|
+
self.getHlxConfig = () => self.state.hlxConfig;
|
|
46
47
|
self.getSiteId = () => self.state.siteId;
|
|
47
48
|
self.getSource = () => self.state.source;
|
|
48
49
|
self.getStatus = () => self.state.status;
|
|
@@ -54,6 +55,12 @@ const SiteCandidate = (data = {}) => {
|
|
|
54
55
|
return self;
|
|
55
56
|
};
|
|
56
57
|
|
|
58
|
+
self.setHlxConfig = (hlxConfig) => {
|
|
59
|
+
self.state.hlxConfig = hlxConfig;
|
|
60
|
+
self.touch();
|
|
61
|
+
return self;
|
|
62
|
+
};
|
|
63
|
+
|
|
57
64
|
self.setSource = (source) => {
|
|
58
65
|
self.state.source = source;
|
|
59
66
|
self.touch();
|
|
@@ -88,6 +95,14 @@ export const createSiteCandidate = (data) => {
|
|
|
88
95
|
throw new Error(`Base URL must be a valid URL: ${newState.baseURL}`);
|
|
89
96
|
}
|
|
90
97
|
|
|
98
|
+
if (newState.hlxConfig && !isObject(newState.hlxConfig)) {
|
|
99
|
+
throw new Error(`HLX Config must be an object: ${newState.hlxConfig}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!newState.hlxConfig) {
|
|
103
|
+
newState.hlxConfig = {};
|
|
104
|
+
}
|
|
105
|
+
|
|
91
106
|
if (!hasText(newState.updatedBy)) {
|
|
92
107
|
newState.updatedBy = DEFAULT_UPDATED_BY;
|
|
93
108
|
}
|
package/src/models/site.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
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';
|
|
17
16
|
import { Config, DEFAULT_CONFIG } from './site/config.js';
|
|
18
17
|
import { DEFAULT_ORGANIZATION_ID } from './organization.js';
|
|
19
18
|
|
|
@@ -34,12 +33,12 @@ export const DEFAULT_DELIVERY_TYPE = DELIVERY_TYPES.AEM_EDGE;
|
|
|
34
33
|
const Site = (data = {}) => {
|
|
35
34
|
const self = Base(data);
|
|
36
35
|
|
|
37
|
-
self.getAuditConfig = () => self.state.auditConfig;
|
|
38
36
|
self.getAudits = () => self.state.audits;
|
|
39
37
|
self.getBaseURL = () => self.state.baseURL;
|
|
40
38
|
self.getConfig = () => self.state.config;
|
|
41
39
|
self.getDeliveryType = () => self.state.deliveryType;
|
|
42
40
|
self.getGitHubURL = () => self.state.gitHubURL;
|
|
41
|
+
self.getHlxConfig = () => self.state.hlxConfig;
|
|
43
42
|
self.getOrganizationId = () => self.state.organizationId;
|
|
44
43
|
self.isLive = () => self.state.isLive;
|
|
45
44
|
self.getIsLiveToggledAt = () => self.state.isLiveToggledAt;
|
|
@@ -81,18 +80,6 @@ const Site = (data = {}) => {
|
|
|
81
80
|
return self;
|
|
82
81
|
}; */
|
|
83
82
|
|
|
84
|
-
self.setAllAuditsDisabled = (disabled) => {
|
|
85
|
-
self.state.auditConfig.updateAuditsDisabled(disabled);
|
|
86
|
-
self.touch();
|
|
87
|
-
return self;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
self.updateAuditTypeConfig = (type, config) => {
|
|
91
|
-
self.state.auditConfig.updateAuditTypeConfig(type, config);
|
|
92
|
-
self.touch();
|
|
93
|
-
return self;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
83
|
/**
|
|
97
84
|
* Updates the site config.
|
|
98
85
|
* @param {string} config - The Site config.
|
|
@@ -136,6 +123,23 @@ const Site = (data = {}) => {
|
|
|
136
123
|
return self;
|
|
137
124
|
};
|
|
138
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Updates the Helix Configuration for this site.
|
|
128
|
+
* @param {object} hlxConfig - The Helix Configuration.
|
|
129
|
+
* @throws {Error} If the provided Helix Configuration is not an object.
|
|
130
|
+
* @return {Base} The updated site.
|
|
131
|
+
*/
|
|
132
|
+
self.updateHlxConfig = (hlxConfig) => {
|
|
133
|
+
if (!isObject(hlxConfig)) {
|
|
134
|
+
throw new Error('HLX Config must be an object');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
self.state.hlxConfig = hlxConfig;
|
|
138
|
+
self.touch();
|
|
139
|
+
|
|
140
|
+
return self;
|
|
141
|
+
};
|
|
142
|
+
|
|
139
143
|
/**
|
|
140
144
|
* Updates the organizationId the site belongs to.
|
|
141
145
|
* @param {string} organizationId - The Org ID.
|
|
@@ -179,6 +183,14 @@ export const createSite = (data) => {
|
|
|
179
183
|
throw new Error(`Base URL must be a valid URL: ${newState.baseURL}`);
|
|
180
184
|
}
|
|
181
185
|
|
|
186
|
+
if (newState.hlxConfig && !isObject(newState.hlxConfig)) {
|
|
187
|
+
throw new Error(`HLX Config must be an object: ${newState.hlxConfig}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!newState.hlxConfig) {
|
|
191
|
+
newState.hlxConfig = {};
|
|
192
|
+
}
|
|
193
|
+
|
|
182
194
|
if (!hasText(newState.organizationId)) {
|
|
183
195
|
newState.organizationId = DEFAULT_ORGANIZATION_ID;
|
|
184
196
|
}
|
|
@@ -196,15 +208,6 @@ export const createSite = (data) => {
|
|
|
196
208
|
newState.audits = [];
|
|
197
209
|
}
|
|
198
210
|
|
|
199
|
-
if (!isObject(newState.auditConfig)) {
|
|
200
|
-
newState.auditConfig = {
|
|
201
|
-
auditsDisabled: false,
|
|
202
|
-
auditTypeConfigs: {},
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
newState.auditConfig = AuditConfig(newState.auditConfig);
|
|
207
|
-
|
|
208
211
|
if (!isObject(newState.config)) {
|
|
209
212
|
newState.config = { ...DEFAULT_CONFIG };
|
|
210
213
|
}
|
|
@@ -110,8 +110,7 @@ export const updateConfiguration = async (
|
|
|
110
110
|
const newConfigurationData = { ...configurationData };
|
|
111
111
|
const latestConfiguration = await getConfiguration(dynamoClient, config);
|
|
112
112
|
|
|
113
|
-
newConfigurationData.version = incrementVersion(latestConfiguration?.
|
|
114
|
-
newConfigurationData.PK = config.pkAllConfigurations;
|
|
113
|
+
newConfigurationData.version = incrementVersion(latestConfiguration?.getVersion());
|
|
115
114
|
|
|
116
115
|
const newConfiguration = createConfiguration(newConfigurationData);
|
|
117
116
|
|
|
@@ -1,60 +0,0 @@
|
|
|
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;
|
|
@@ -1,85 +0,0 @@
|
|
|
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;
|