@adobe/spacecat-shared-data-access 1.61.19 → 2.0.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 +19 -0
- package/package.json +5 -6
- package/src/index.d.ts +4 -934
- package/src/index.js +1 -91
- package/src/{v2 → models}/index.d.ts +14 -3
- package/src/{v2/models → models}/organization/organization.schema.js +1 -1
- package/src/{v2/models → models}/site/site.schema.js +1 -1
- package/src/service/index.d.ts +20 -0
- package/src/service/index.js +6 -46
- package/src/dto/api-key.js +0 -58
- package/src/dto/audit.js +0 -80
- package/src/dto/configuration.js +0 -49
- package/src/dto/dto-utils.js +0 -30
- package/src/dto/experiment.js +0 -66
- package/src/dto/import-job.js +0 -76
- package/src/dto/import-url.js +0 -55
- package/src/dto/key-event.js +0 -52
- package/src/dto/organization.js +0 -54
- package/src/dto/site-candidate.js +0 -54
- package/src/dto/site-top-page.js +0 -52
- package/src/dto/site.js +0 -62
- package/src/models/api-key/api-key.js +0 -182
- package/src/models/audit.js +0 -146
- package/src/models/base.js +0 -42
- package/src/models/configuration.js +0 -194
- package/src/models/experiment.js +0 -67
- package/src/models/importer/import-constants.js +0 -40
- package/src/models/importer/import-job.js +0 -252
- package/src/models/importer/import-url.js +0 -115
- package/src/models/key-event.js +0 -81
- package/src/models/organization.js +0 -120
- package/src/models/site-candidate.js +0 -111
- package/src/models/site-top-page.js +0 -62
- package/src/models/site.js +0 -218
- package/src/service/api-key/accessPatterns.js +0 -110
- package/src/service/api-key/index.js +0 -37
- package/src/service/audits/accessPatterns.js +0 -284
- package/src/service/audits/index.js +0 -72
- package/src/service/configurations/accessPatterns.js +0 -123
- package/src/service/configurations/index.js +0 -38
- package/src/service/experiments/accessPatterns.js +0 -98
- package/src/service/experiments/index.js +0 -40
- package/src/service/import-job/accessPatterns.js +0 -134
- package/src/service/import-job/index.js +0 -60
- package/src/service/import-url/accessPatterns.js +0 -153
- package/src/service/import-url/index.js +0 -53
- package/src/service/key-events/accessPatterns.js +0 -92
- package/src/service/key-events/index.js +0 -38
- package/src/service/organizations/accessPatterns.js +0 -160
- package/src/service/organizations/index.js +0 -51
- package/src/service/site-candidates/accessPatterns.js +0 -112
- package/src/service/site-candidates/index.js +0 -48
- package/src/service/site-top-pages/accessPatterns.js +0 -83
- package/src/service/site-top-pages/index.js +0 -42
- package/src/service/sites/accessPatterns.js +0 -467
- package/src/service/sites/index.js +0 -116
- package/src/v2/index.js +0 -15
- package/src/v2/models/index.d.ts +0 -26
- /package/src/{v2/errors → errors}/data-access.error.js +0 -0
- /package/src/{v2/errors → errors}/index.d.ts +0 -0
- /package/src/{v2/errors → errors}/index.js +0 -0
- /package/src/{v2/errors → errors}/reference.error.js +0 -0
- /package/src/{v2/errors → errors}/schema-validation.error.js +0 -0
- /package/src/{v2/errors → errors}/schema.builder.error.js +0 -0
- /package/src/{v2/errors → errors}/schema.error.js +0 -0
- /package/src/{v2/errors → errors}/validation.error.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.collection.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.model.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.schema.js +0 -0
- /package/src/{v2/models → models}/api-key/index.d.ts +0 -0
- /package/src/{v2/models → models}/api-key/index.js +0 -0
- /package/src/{v2/models → models}/audit/audit.collection.js +0 -0
- /package/src/{v2/models → models}/audit/audit.model.js +0 -0
- /package/src/{v2/models → models}/audit/audit.schema.js +0 -0
- /package/src/{v2/models → models}/audit/index.d.ts +0 -0
- /package/src/{v2/models → models}/audit/index.js +0 -0
- /package/src/{v2/models → models}/base/base.collection.js +0 -0
- /package/src/{v2/models → models}/base/base.model.js +0 -0
- /package/src/{v2/models → models}/base/entity.registry.js +0 -0
- /package/src/{v2/models → models}/base/index.d.ts +0 -0
- /package/src/{v2/models → models}/base/index.js +0 -0
- /package/src/{v2/models → models}/base/reference.js +0 -0
- /package/src/{v2/models → models}/base/schema.builder.js +0 -0
- /package/src/{v2/models → models}/base/schema.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.collection.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.model.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.schema.js +0 -0
- /package/src/{v2/models → models}/configuration/index.d.ts +0 -0
- /package/src/{v2/models → models}/configuration/index.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.collection.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.model.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.schema.js +0 -0
- /package/src/{v2/models → models}/experiment/index.d.ts +0 -0
- /package/src/{v2/models → models}/experiment/index.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.collection.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.model.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.schema.js +0 -0
- /package/src/{v2/models → models}/import-job/index.d.ts +0 -0
- /package/src/{v2/models → models}/import-job/index.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.collection.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.model.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.schema.js +0 -0
- /package/src/{v2/models → models}/import-url/index.d.ts +0 -0
- /package/src/{v2/models → models}/import-url/index.js +0 -0
- /package/src/{v2/models → models}/index.js +0 -0
- /package/src/{v2/models → models}/key-event/index.d.ts +0 -0
- /package/src/{v2/models → models}/key-event/index.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.collection.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.model.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.schema.js +0 -0
- /package/src/{v2/models → models}/latest-audit/index.d.ts +0 -0
- /package/src/{v2/models → models}/latest-audit/index.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.collection.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.model.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.schema.js +0 -0
- /package/src/{v2/models → models}/opportunity/index.d.ts +0 -0
- /package/src/{v2/models → models}/opportunity/index.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.collection.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.model.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.schema.js +0 -0
- /package/src/{v2/models → models}/organization/index.d.ts +0 -0
- /package/src/{v2/models → models}/organization/index.js +0 -0
- /package/src/{v2/models → models}/organization/organization.collection.js +0 -0
- /package/src/{v2/models → models}/organization/organization.model.js +0 -0
- /package/src/{v2/models → models}/site/index.d.ts +0 -0
- /package/src/{v2/models → models}/site/index.js +0 -0
- /package/src/{v2/models → models}/site/site.collection.js +0 -0
- /package/src/{v2/models → models}/site/site.model.js +0 -0
- /package/src/{v2/models → models}/site-candidate/index.d.ts +0 -0
- /package/src/{v2/models → models}/site-candidate/index.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.collection.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.model.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.schema.js +0 -0
- /package/src/{v2/models → models}/site-top-page/index.d.ts +0 -0
- /package/src/{v2/models → models}/site-top-page/index.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.collection.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.model.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.schema.js +0 -0
- /package/src/{v2/models → models}/suggestion/index.d.ts +0 -0
- /package/src/{v2/models → models}/suggestion/index.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.collection.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.model.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.schema.js +0 -0
- /package/src/{v2/readme.md → readme.md} +0 -0
- /package/src/{v2/util → util}/accessor.utils.js +0 -0
- /package/src/{v2/util → util}/guards.d.ts +0 -0
- /package/src/{v2/util → util}/guards.js +0 -0
- /package/src/{v2/util → util}/index.d.ts +0 -0
- /package/src/{v2/util → util}/index.js +0 -0
- /package/src/{v2/util → util}/patcher.js +0 -0
- /package/src/{v2/util → util}/util.js +0 -0
package/src/models/key-event.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 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 { hasText, isIsoDate } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { Base } from './base.js';
|
|
16
|
-
|
|
17
|
-
export const KEY_EVENT_TYPES = {
|
|
18
|
-
PERFORMANCE: 'PERFORMANCE',
|
|
19
|
-
SEO: 'SEO',
|
|
20
|
-
CONTENT: 'CONTENT',
|
|
21
|
-
CODE: 'CODE',
|
|
22
|
-
THIRD_PARTY: 'THIRD PARTY',
|
|
23
|
-
EXPERIMENTATION: 'EXPERIMENTATION',
|
|
24
|
-
NETWORK: 'NETWORK',
|
|
25
|
-
STATUS_CHANGE: 'STATUS CHANGE',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new Key Event.
|
|
30
|
-
*
|
|
31
|
-
* @param {object} data - key event data
|
|
32
|
-
* @returns {Readonly<KeyEvent>} new key event
|
|
33
|
-
*/
|
|
34
|
-
const KeyEvent = (data = {}) => {
|
|
35
|
-
const self = Base(data);
|
|
36
|
-
|
|
37
|
-
self.getName = () => self.state.name;
|
|
38
|
-
self.getSiteId = () => self.state.siteId;
|
|
39
|
-
self.getType = () => self.state.type;
|
|
40
|
-
self.getTime = () => self.state.time;
|
|
41
|
-
|
|
42
|
-
// no set functions since all values are required at creation time
|
|
43
|
-
|
|
44
|
-
return Object.freeze(self);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new Key Event.
|
|
49
|
-
*
|
|
50
|
-
* @param {object} data - key event data
|
|
51
|
-
* @returns {Readonly<KeyEvent>} new key event
|
|
52
|
-
*/
|
|
53
|
-
export const createKeyEvent = (data) => {
|
|
54
|
-
const newState = { ...data };
|
|
55
|
-
|
|
56
|
-
if (!hasText(newState.siteId)) {
|
|
57
|
-
throw new Error('Required field "siteId" is missing');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!hasText(newState.name)) {
|
|
61
|
-
throw new Error('Required field "name" is missing');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!hasText(newState.type)) {
|
|
65
|
-
throw new Error('Required field "type" is missing');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!Object.values(KEY_EVENT_TYPES).includes(newState.type.toUpperCase())) {
|
|
69
|
-
throw new Error(`Unknown value for "type": ${newState.type}`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (hasText(newState.time) && !isIsoDate(newState.time)) {
|
|
73
|
-
throw new Error('"Time" should be a valid ISO string');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!hasText(newState.time)) {
|
|
77
|
-
newState.time = new Date().toISOString();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return KeyEvent(newState);
|
|
81
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 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 { hasText, isObject } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { Base } from './base.js';
|
|
16
|
-
import { Config, DEFAULT_CONFIG } from './site/config.js';
|
|
17
|
-
|
|
18
|
-
export const DEFAULT_ORGANIZATION_ID = 'default';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new Organization.
|
|
22
|
-
*
|
|
23
|
-
* @param {object} data - organization data
|
|
24
|
-
* @returns {Readonly<Organization>} organization - new organization
|
|
25
|
-
*/
|
|
26
|
-
const Organization = (data = {}) => {
|
|
27
|
-
const self = Base(data);
|
|
28
|
-
|
|
29
|
-
self.getConfig = () => self.state.config;
|
|
30
|
-
self.getName = () => self.state.name;
|
|
31
|
-
self.getImsOrgId = () => self.state.imsOrgId;
|
|
32
|
-
self.getFulfillableItems = () => self.state.fulfillableItems;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Updates the IMS Org ID belonging to the organization.
|
|
36
|
-
* @param {string} imsOrgId - The IMS Org ID.
|
|
37
|
-
* @return {Base} The updated organization.
|
|
38
|
-
*/
|
|
39
|
-
self.updateImsOrgId = (imsOrgId) => {
|
|
40
|
-
if (!hasText(imsOrgId)) {
|
|
41
|
-
throw new Error('IMS Org ID must be provided');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
self.state.imsOrgId = imsOrgId;
|
|
45
|
-
self.touch();
|
|
46
|
-
|
|
47
|
-
return self;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Updates the organization name.
|
|
52
|
-
* @param {string} name - The name of the organization.
|
|
53
|
-
* @return {Base} The updated organization.
|
|
54
|
-
*/
|
|
55
|
-
self.updateName = (name) => {
|
|
56
|
-
if (!hasText(name)) {
|
|
57
|
-
throw new Error('Org name must be provided');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
self.state.name = name;
|
|
61
|
-
self.touch();
|
|
62
|
-
|
|
63
|
-
return self;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Updates the organization config.
|
|
68
|
-
* @param {string} config - The Org config.
|
|
69
|
-
* @return {Base} The updated organization.
|
|
70
|
-
*/
|
|
71
|
-
self.updateConfig = (config) => {
|
|
72
|
-
if (!isObject(config)) {
|
|
73
|
-
throw new Error('Config must be provided');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
self.state.config = Config(config);
|
|
77
|
-
self.touch();
|
|
78
|
-
|
|
79
|
-
return self;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
self.updateFulfillableItems = (fulfillableItems) => {
|
|
83
|
-
if (!isObject(fulfillableItems)) {
|
|
84
|
-
throw new Error('Fulfillable items object must be provided');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
self.state.fulfillableItems = fulfillableItems;
|
|
88
|
-
self.touch();
|
|
89
|
-
|
|
90
|
-
return self;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return Object.freeze(self);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Creates a new Organization.
|
|
98
|
-
*
|
|
99
|
-
* @param {object} data - organization data
|
|
100
|
-
* @returns {Readonly<Organization>} organization - new organization
|
|
101
|
-
*/
|
|
102
|
-
export const createOrganization = (data) => {
|
|
103
|
-
const newState = { ...data };
|
|
104
|
-
|
|
105
|
-
if (!isObject(newState.config)) {
|
|
106
|
-
newState.config = { ...DEFAULT_CONFIG };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!hasText(newState.name)) {
|
|
110
|
-
throw new Error('Org name must be provided');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!hasText(newState.imsOrgId)) {
|
|
114
|
-
newState.imsOrgId = DEFAULT_ORGANIZATION_ID;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
newState.config = Config(newState.config);
|
|
118
|
-
|
|
119
|
-
return Organization(newState);
|
|
120
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 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 { hasText, isObject, isValidUrl } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { Base } from './base.js';
|
|
16
|
-
|
|
17
|
-
export const DEFAULT_UPDATED_BY = 'spacecat';
|
|
18
|
-
|
|
19
|
-
export const SITE_CANDIDATE_SOURCES = {
|
|
20
|
-
SPACECAT_SLACK_BOT: 'SPACECAT_SLACK_BOT',
|
|
21
|
-
RUM: 'RUM',
|
|
22
|
-
CDN: 'CDN',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const SITE_CANDIDATE_STATUS = {
|
|
26
|
-
PENDING: 'PENDING', // site candidate notification sent and waiting for human input
|
|
27
|
-
IGNORED: 'IGNORED', // site candidate discarded: not to be added to star catalogue
|
|
28
|
-
APPROVED: 'APPROVED', // site candidate is added to star catalogue
|
|
29
|
-
ERROR: 'ERROR', // site candidate is discovered
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new Site Candidate.
|
|
34
|
-
*
|
|
35
|
-
* @param {object} data - site candidate data
|
|
36
|
-
* @returns {Readonly<SiteCandidate>} new site candidate
|
|
37
|
-
*/
|
|
38
|
-
const SiteCandidate = (data = {}) => {
|
|
39
|
-
const self = Base({
|
|
40
|
-
updatedBy: DEFAULT_UPDATED_BY,
|
|
41
|
-
...data,
|
|
42
|
-
});
|
|
43
|
-
delete self.state.id; // no id property used in SiteCandidate modal
|
|
44
|
-
|
|
45
|
-
self.getBaseURL = () => self.state.baseURL;
|
|
46
|
-
self.getHlxConfig = () => self.state.hlxConfig;
|
|
47
|
-
self.getSiteId = () => self.state.siteId;
|
|
48
|
-
self.getSource = () => self.state.source;
|
|
49
|
-
self.getStatus = () => self.state.status;
|
|
50
|
-
self.getUpdatedBy = () => self.state.updatedBy;
|
|
51
|
-
|
|
52
|
-
self.setSiteId = (siteId) => {
|
|
53
|
-
self.state.siteId = siteId;
|
|
54
|
-
self.touch();
|
|
55
|
-
return self;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
self.setHlxConfig = (hlxConfig) => {
|
|
59
|
-
self.state.hlxConfig = hlxConfig;
|
|
60
|
-
self.touch();
|
|
61
|
-
return self;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
self.setSource = (source) => {
|
|
65
|
-
self.state.source = source;
|
|
66
|
-
self.touch();
|
|
67
|
-
return self;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
self.setStatus = (status) => {
|
|
71
|
-
self.state.status = status;
|
|
72
|
-
self.touch();
|
|
73
|
-
return self;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
self.setUpdatedBy = (updatedBy) => {
|
|
77
|
-
self.state.updatedBy = updatedBy;
|
|
78
|
-
self.touch();
|
|
79
|
-
return self;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return Object.freeze(self);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Creates a new Site Candidate.
|
|
87
|
-
*
|
|
88
|
-
* @param {object} data - site candidate data
|
|
89
|
-
* @returns {Readonly<SiteCandidate>} new site candidate
|
|
90
|
-
*/
|
|
91
|
-
export const createSiteCandidate = (data) => {
|
|
92
|
-
const newState = { ...data };
|
|
93
|
-
|
|
94
|
-
if (!isValidUrl(newState.baseURL)) {
|
|
95
|
-
throw new Error(`Base URL must be a valid URL: ${newState.baseURL}`);
|
|
96
|
-
}
|
|
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
|
-
|
|
106
|
-
if (!hasText(newState.updatedBy)) {
|
|
107
|
-
newState.updatedBy = DEFAULT_UPDATED_BY;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return SiteCandidate(newState);
|
|
111
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 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 {
|
|
14
|
-
hasText, isInteger, isIsoDate, isValidUrl,
|
|
15
|
-
} from '@adobe/spacecat-shared-utils';
|
|
16
|
-
import { Base } from './base.js';
|
|
17
|
-
|
|
18
|
-
export const DEFAULT_GEO = 'global';
|
|
19
|
-
|
|
20
|
-
const SiteTopPage = (data = {}) => {
|
|
21
|
-
const self = Base(data);
|
|
22
|
-
|
|
23
|
-
self.getSiteId = () => self.state.siteId;
|
|
24
|
-
self.getURL = () => self.state.url;
|
|
25
|
-
self.getTraffic = () => self.state.traffic;
|
|
26
|
-
self.getTopKeyword = () => self.state.topKeyword;
|
|
27
|
-
self.getSource = () => self.state.source.toLowerCase();
|
|
28
|
-
self.getGeo = () => self.state.geo;
|
|
29
|
-
self.getImportedAt = () => self.state.importedAt;
|
|
30
|
-
|
|
31
|
-
return Object.freeze(self);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const createSiteTopPage = (data) => {
|
|
35
|
-
const newState = { ...data };
|
|
36
|
-
|
|
37
|
-
if (!hasText(newState.siteId)) {
|
|
38
|
-
throw new Error('Site ID must be provided');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!isValidUrl(newState.url)) {
|
|
42
|
-
throw new Error('Valid Url must be provided');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!isInteger(newState.traffic)) {
|
|
46
|
-
throw new Error('Traffic must be provided');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!hasText(newState.source)) {
|
|
50
|
-
throw new Error('Source must be provided');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!hasText(newState.geo)) {
|
|
54
|
-
newState.geo = DEFAULT_GEO;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!isIsoDate(newState.importedAt)) {
|
|
58
|
-
throw new Error('Imported at must be a valid ISO date');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return SiteTopPage(newState);
|
|
62
|
-
};
|
package/src/models/site.js
DELETED
|
@@ -1,218 +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 { hasText, isObject, isValidUrl } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { Base } from './base.js';
|
|
16
|
-
import { Config, DEFAULT_CONFIG } from './site/config.js';
|
|
17
|
-
import { DEFAULT_ORGANIZATION_ID } from './organization.js';
|
|
18
|
-
|
|
19
|
-
export const DELIVERY_TYPES = {
|
|
20
|
-
AEM_CS: 'aem_cs',
|
|
21
|
-
AEM_EDGE: 'aem_edge',
|
|
22
|
-
OTHER: 'other',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const DEFAULT_DELIVERY_TYPE = DELIVERY_TYPES.AEM_EDGE;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Creates a new Site.
|
|
29
|
-
*
|
|
30
|
-
* @param {object} data - site data
|
|
31
|
-
* @returns {Readonly<Site>} site - new site
|
|
32
|
-
*/
|
|
33
|
-
const Site = (data = {}) => {
|
|
34
|
-
const self = Base(data);
|
|
35
|
-
|
|
36
|
-
self.getAudits = () => self.state.audits;
|
|
37
|
-
self.getBaseURL = () => self.state.baseURL;
|
|
38
|
-
self.getConfig = () => self.state.config;
|
|
39
|
-
self.getDeliveryType = () => self.state.deliveryType;
|
|
40
|
-
self.getGitHubURL = () => self.state.gitHubURL;
|
|
41
|
-
self.getHlxConfig = () => self.state.hlxConfig;
|
|
42
|
-
self.getOrganizationId = () => self.state.organizationId;
|
|
43
|
-
self.isLive = () => self.state.isLive;
|
|
44
|
-
self.getIsLiveToggledAt = () => self.state.isLiveToggledAt;
|
|
45
|
-
|
|
46
|
-
// TODO: updating the baseURL is not supported yet, it will require a transact write
|
|
47
|
-
// on dynamodb (put then delete) since baseURL is part of the primary key, something like:
|
|
48
|
-
// const updateSiteBaseURL = async (oldBaseURL, updatedSiteData) => {
|
|
49
|
-
// const params = {
|
|
50
|
-
// TransactItems: [
|
|
51
|
-
// {
|
|
52
|
-
// Put: {
|
|
53
|
-
// TableName: 'YourSiteTableName',
|
|
54
|
-
// Item: updatedSiteData,
|
|
55
|
-
// },
|
|
56
|
-
// },
|
|
57
|
-
// {
|
|
58
|
-
// Delete: {
|
|
59
|
-
// TableName: 'YourSiteTableName',
|
|
60
|
-
// Key: {
|
|
61
|
-
// baseURL: oldBaseURL,
|
|
62
|
-
// },
|
|
63
|
-
// },
|
|
64
|
-
// },
|
|
65
|
-
// ],
|
|
66
|
-
// };
|
|
67
|
-
//
|
|
68
|
-
// await dynamoDbClient.transactWrite(params).promise();
|
|
69
|
-
//
|
|
70
|
-
// return createSite(updatedSiteData);
|
|
71
|
-
// };
|
|
72
|
-
/* self.updateBaseURL = (baseURL) => {
|
|
73
|
-
if (!isValidUrl(baseURL)) {
|
|
74
|
-
throw new Error('Base URL must be a valid URL');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
self.state.baseURL = baseURL;
|
|
78
|
-
self.touch();
|
|
79
|
-
|
|
80
|
-
return self;
|
|
81
|
-
}; */
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Updates the site config.
|
|
85
|
-
* @param {string} config - The Site config.
|
|
86
|
-
* @return {Base} The updated site.
|
|
87
|
-
*/
|
|
88
|
-
self.updateConfig = (config) => {
|
|
89
|
-
if (!isObject(config)) {
|
|
90
|
-
throw new Error('Config must be provided');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
self.state.config = Config(config);
|
|
94
|
-
self.touch();
|
|
95
|
-
|
|
96
|
-
return self;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
self.updateDeliveryType = (deliveryType) => {
|
|
100
|
-
if (!Object.values(DELIVERY_TYPES).includes(deliveryType)) {
|
|
101
|
-
throw new Error(`Invalid delivery type: ${deliveryType}`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
self.state.deliveryType = deliveryType;
|
|
105
|
-
self.touch();
|
|
106
|
-
|
|
107
|
-
return self;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Updates the GitHub URL belonging to the site.
|
|
112
|
-
* @param {string} gitHubURL - The GitHub URL.
|
|
113
|
-
* @return {Base} The updated site.
|
|
114
|
-
*/
|
|
115
|
-
self.updateGitHubURL = (gitHubURL) => {
|
|
116
|
-
if (!isValidUrl(gitHubURL)) {
|
|
117
|
-
throw new Error('GitHub URL must be a valid URL');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
self.state.gitHubURL = gitHubURL;
|
|
121
|
-
self.touch();
|
|
122
|
-
|
|
123
|
-
return self;
|
|
124
|
-
};
|
|
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
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Updates the organizationId the site belongs to.
|
|
145
|
-
* @param {string} organizationId - The Org ID.
|
|
146
|
-
* @return {Base} The updated site.
|
|
147
|
-
*/
|
|
148
|
-
self.updateOrganizationId = (organizationId) => {
|
|
149
|
-
self.state.organizationId = organizationId;
|
|
150
|
-
self.touch();
|
|
151
|
-
|
|
152
|
-
return self;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
self.setAudits = (audits) => {
|
|
156
|
-
self.state.audits = audits;
|
|
157
|
-
return self;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Sets whether the site is live.
|
|
162
|
-
* @return {Base} The updated site.
|
|
163
|
-
*/
|
|
164
|
-
self.toggleLive = () => {
|
|
165
|
-
self.state.isLive = !self.state.isLive;
|
|
166
|
-
self.state.isLiveToggledAt = new Date().toISOString();
|
|
167
|
-
return self;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return Object.freeze(self);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Creates a new Site.
|
|
175
|
-
*
|
|
176
|
-
* @param {object} data - site data
|
|
177
|
-
* @returns {Readonly<Site>} site - new site
|
|
178
|
-
*/
|
|
179
|
-
export const createSite = (data) => {
|
|
180
|
-
const newState = { ...data };
|
|
181
|
-
|
|
182
|
-
if (!isValidUrl(newState.baseURL)) {
|
|
183
|
-
throw new Error(`Base URL must be a valid URL: ${newState.baseURL}`);
|
|
184
|
-
}
|
|
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
|
-
|
|
194
|
-
if (!hasText(newState.organizationId)) {
|
|
195
|
-
newState.organizationId = DEFAULT_ORGANIZATION_ID;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
newState.deliveryType = newState.deliveryType || DEFAULT_DELIVERY_TYPE;
|
|
199
|
-
if (!Object.values(DELIVERY_TYPES).includes(newState.deliveryType)) {
|
|
200
|
-
throw new Error(`Invalid delivery type: ${newState.deliveryType}`);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (!Object.prototype.hasOwnProperty.call(newState, 'isLive')) {
|
|
204
|
-
newState.isLive = false;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (!Array.isArray(newState.audits)) {
|
|
208
|
-
newState.audits = [];
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (!isObject(newState.config)) {
|
|
212
|
-
newState.config = { ...DEFAULT_CONFIG };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
newState.config = Config(newState.config);
|
|
216
|
-
|
|
217
|
-
return Site(newState);
|
|
218
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 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 { ApiKeyDto } from '../../dto/api-key.js';
|
|
14
|
-
import { createApiKey } from '../../models/api-key/api-key.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Get ApiKey by Hashed Key
|
|
18
|
-
* @param {string} hashedApiKey
|
|
19
|
-
* @param {DynamoClient} dynamoClient
|
|
20
|
-
* @param {Object} config
|
|
21
|
-
* @param {Logger} log
|
|
22
|
-
* @returns {Promise<ApiKey>}
|
|
23
|
-
*/
|
|
24
|
-
export const getApiKeyByHashedApiKey = async (hashedApiKey, dynamoClient, log, config) => {
|
|
25
|
-
const items = await dynamoClient.query({
|
|
26
|
-
TableName: config.tableNameApiKeys,
|
|
27
|
-
IndexName: config.indexNameApiKeyByHashedApiKey,
|
|
28
|
-
KeyConditionExpression: '#hashedApiKey = :hashedApiKey',
|
|
29
|
-
ExpressionAttributeNames: {
|
|
30
|
-
'#hashedApiKey': 'hashedApiKey',
|
|
31
|
-
},
|
|
32
|
-
ExpressionAttributeValues: {
|
|
33
|
-
':hashedApiKey': hashedApiKey,
|
|
34
|
-
},
|
|
35
|
-
Limit: 1,
|
|
36
|
-
});
|
|
37
|
-
return items.length > 0 ? ApiKeyDto.fromDynamoItem(items[0]) : null;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Create new ApiKey
|
|
42
|
-
* @param {ApiKey} apiKey
|
|
43
|
-
* @param {DynamoClient} dynamoClient
|
|
44
|
-
* @param {Object} config
|
|
45
|
-
* @param {Logger} log
|
|
46
|
-
* @returns {Promise<ApiKey>}
|
|
47
|
-
*/
|
|
48
|
-
export const createNewApiKey = async (apiKey, dynamoClient, config, log) => {
|
|
49
|
-
const item = createApiKey(apiKey);
|
|
50
|
-
await dynamoClient.putItem(config.tableNameApiKeys, ApiKeyDto.toDynamoItem(item), log);
|
|
51
|
-
return item;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get ApiKeys by IMS User ID and IMS Org ID
|
|
56
|
-
* @param imsUserId
|
|
57
|
-
* @param imsOrgId
|
|
58
|
-
* @param dynamoClient
|
|
59
|
-
* @param config
|
|
60
|
-
* @returns {Promise<ApiKey[]>}
|
|
61
|
-
*/
|
|
62
|
-
export const getApiKeysByImsUserIdAndImsOrgId = async (
|
|
63
|
-
imsUserId,
|
|
64
|
-
imsOrgId,
|
|
65
|
-
dynamoClient,
|
|
66
|
-
config,
|
|
67
|
-
) => {
|
|
68
|
-
const items = await dynamoClient.query({
|
|
69
|
-
TableName: config.tableNameApiKeys,
|
|
70
|
-
IndexName: config.indexNameApiKeyByImsUserIdAndImsOrgId,
|
|
71
|
-
KeyConditionExpression: '#imsUserId = :imsUserId AND #imsOrgId = :imsOrgId',
|
|
72
|
-
ExpressionAttributeNames: {
|
|
73
|
-
'#imsUserId': 'imsUserId',
|
|
74
|
-
'#imsOrgId': 'imsOrgId',
|
|
75
|
-
},
|
|
76
|
-
ExpressionAttributeValues: {
|
|
77
|
-
':imsUserId': imsUserId,
|
|
78
|
-
':imsOrgId': imsOrgId,
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
return items.map((item) => ApiKeyDto.fromDynamoItem(item));
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get ApiKey by ID
|
|
86
|
-
* @param id
|
|
87
|
-
* @param dynamoClient
|
|
88
|
-
* @param config
|
|
89
|
-
* @returns {Promise<ApiKey|null>}
|
|
90
|
-
*/
|
|
91
|
-
export const getApiKeyById = async (id, dynamoClient, config) => {
|
|
92
|
-
const item = await dynamoClient.getItem(config.tableNameApiKeys, { id });
|
|
93
|
-
return item ? ApiKeyDto.fromDynamoItem(item) : null;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Update ApiKey
|
|
98
|
-
* @param apiKey
|
|
99
|
-
* @param dynamoClient
|
|
100
|
-
* @param config
|
|
101
|
-
* @returns {Promise<ApiKey>}
|
|
102
|
-
*/
|
|
103
|
-
export const updateApiKey = async (apiKey, dynamoClient, config) => {
|
|
104
|
-
const existingApiKey = await getApiKeyById(apiKey.getId(), dynamoClient, config);
|
|
105
|
-
if (!existingApiKey) {
|
|
106
|
-
throw new Error(`API Key with id ${apiKey.getId()} not found`);
|
|
107
|
-
}
|
|
108
|
-
await dynamoClient.putItem(config.tableNameApiKeys, ApiKeyDto.toDynamoItem(apiKey));
|
|
109
|
-
return apiKey;
|
|
110
|
-
};
|