@adobe/spacecat-shared-data-access 1.61.18 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.json +1 -2
  3. package/src/index.d.ts +4 -934
  4. package/src/index.js +1 -91
  5. package/src/{v2/models → models}/base/base.model.js +16 -3
  6. package/src/{v2 → models}/index.d.ts +14 -3
  7. package/src/{v2/models → models}/organization/organization.schema.js +1 -1
  8. package/src/{v2/models → models}/site/site.schema.js +1 -1
  9. package/src/service/index.d.ts +20 -0
  10. package/src/service/index.js +6 -46
  11. package/src/dto/api-key.js +0 -58
  12. package/src/dto/audit.js +0 -80
  13. package/src/dto/configuration.js +0 -49
  14. package/src/dto/dto-utils.js +0 -30
  15. package/src/dto/experiment.js +0 -66
  16. package/src/dto/import-job.js +0 -76
  17. package/src/dto/import-url.js +0 -55
  18. package/src/dto/key-event.js +0 -52
  19. package/src/dto/organization.js +0 -54
  20. package/src/dto/site-candidate.js +0 -54
  21. package/src/dto/site-top-page.js +0 -52
  22. package/src/dto/site.js +0 -62
  23. package/src/models/api-key/api-key.js +0 -182
  24. package/src/models/audit.js +0 -146
  25. package/src/models/base.js +0 -42
  26. package/src/models/configuration.js +0 -194
  27. package/src/models/experiment.js +0 -67
  28. package/src/models/importer/import-constants.js +0 -40
  29. package/src/models/importer/import-job.js +0 -252
  30. package/src/models/importer/import-url.js +0 -115
  31. package/src/models/key-event.js +0 -81
  32. package/src/models/organization.js +0 -120
  33. package/src/models/site-candidate.js +0 -111
  34. package/src/models/site-top-page.js +0 -62
  35. package/src/models/site.js +0 -218
  36. package/src/service/api-key/accessPatterns.js +0 -110
  37. package/src/service/api-key/index.js +0 -37
  38. package/src/service/audits/accessPatterns.js +0 -284
  39. package/src/service/audits/index.js +0 -72
  40. package/src/service/configurations/accessPatterns.js +0 -123
  41. package/src/service/configurations/index.js +0 -38
  42. package/src/service/experiments/accessPatterns.js +0 -98
  43. package/src/service/experiments/index.js +0 -40
  44. package/src/service/import-job/accessPatterns.js +0 -134
  45. package/src/service/import-job/index.js +0 -60
  46. package/src/service/import-url/accessPatterns.js +0 -153
  47. package/src/service/import-url/index.js +0 -53
  48. package/src/service/key-events/accessPatterns.js +0 -92
  49. package/src/service/key-events/index.js +0 -38
  50. package/src/service/organizations/accessPatterns.js +0 -160
  51. package/src/service/organizations/index.js +0 -51
  52. package/src/service/site-candidates/accessPatterns.js +0 -112
  53. package/src/service/site-candidates/index.js +0 -48
  54. package/src/service/site-top-pages/accessPatterns.js +0 -83
  55. package/src/service/site-top-pages/index.js +0 -42
  56. package/src/service/sites/accessPatterns.js +0 -467
  57. package/src/service/sites/index.js +0 -116
  58. package/src/v2/index.js +0 -15
  59. package/src/v2/models/index.d.ts +0 -26
  60. /package/src/{v2/errors → errors}/data-access.error.js +0 -0
  61. /package/src/{v2/errors → errors}/index.d.ts +0 -0
  62. /package/src/{v2/errors → errors}/index.js +0 -0
  63. /package/src/{v2/errors → errors}/reference.error.js +0 -0
  64. /package/src/{v2/errors → errors}/schema-validation.error.js +0 -0
  65. /package/src/{v2/errors → errors}/schema.builder.error.js +0 -0
  66. /package/src/{v2/errors → errors}/schema.error.js +0 -0
  67. /package/src/{v2/errors → errors}/validation.error.js +0 -0
  68. /package/src/{v2/models → models}/api-key/api-key.collection.js +0 -0
  69. /package/src/{v2/models → models}/api-key/api-key.model.js +0 -0
  70. /package/src/{v2/models → models}/api-key/api-key.schema.js +0 -0
  71. /package/src/{v2/models → models}/api-key/index.d.ts +0 -0
  72. /package/src/{v2/models → models}/api-key/index.js +0 -0
  73. /package/src/{v2/models → models}/audit/audit.collection.js +0 -0
  74. /package/src/{v2/models → models}/audit/audit.model.js +0 -0
  75. /package/src/{v2/models → models}/audit/audit.schema.js +0 -0
  76. /package/src/{v2/models → models}/audit/index.d.ts +0 -0
  77. /package/src/{v2/models → models}/audit/index.js +0 -0
  78. /package/src/{v2/models → models}/base/base.collection.js +0 -0
  79. /package/src/{v2/models → models}/base/entity.registry.js +0 -0
  80. /package/src/{v2/models → models}/base/index.d.ts +0 -0
  81. /package/src/{v2/models → models}/base/index.js +0 -0
  82. /package/src/{v2/models → models}/base/reference.js +0 -0
  83. /package/src/{v2/models → models}/base/schema.builder.js +0 -0
  84. /package/src/{v2/models → models}/base/schema.js +0 -0
  85. /package/src/{v2/models → models}/configuration/configuration.collection.js +0 -0
  86. /package/src/{v2/models → models}/configuration/configuration.model.js +0 -0
  87. /package/src/{v2/models → models}/configuration/configuration.schema.js +0 -0
  88. /package/src/{v2/models → models}/configuration/index.d.ts +0 -0
  89. /package/src/{v2/models → models}/configuration/index.js +0 -0
  90. /package/src/{v2/models → models}/experiment/experiment.collection.js +0 -0
  91. /package/src/{v2/models → models}/experiment/experiment.model.js +0 -0
  92. /package/src/{v2/models → models}/experiment/experiment.schema.js +0 -0
  93. /package/src/{v2/models → models}/experiment/index.d.ts +0 -0
  94. /package/src/{v2/models → models}/experiment/index.js +0 -0
  95. /package/src/{v2/models → models}/import-job/import-job.collection.js +0 -0
  96. /package/src/{v2/models → models}/import-job/import-job.model.js +0 -0
  97. /package/src/{v2/models → models}/import-job/import-job.schema.js +0 -0
  98. /package/src/{v2/models → models}/import-job/index.d.ts +0 -0
  99. /package/src/{v2/models → models}/import-job/index.js +0 -0
  100. /package/src/{v2/models → models}/import-url/import-url.collection.js +0 -0
  101. /package/src/{v2/models → models}/import-url/import-url.model.js +0 -0
  102. /package/src/{v2/models → models}/import-url/import-url.schema.js +0 -0
  103. /package/src/{v2/models → models}/import-url/index.d.ts +0 -0
  104. /package/src/{v2/models → models}/import-url/index.js +0 -0
  105. /package/src/{v2/models → models}/index.js +0 -0
  106. /package/src/{v2/models → models}/key-event/index.d.ts +0 -0
  107. /package/src/{v2/models → models}/key-event/index.js +0 -0
  108. /package/src/{v2/models → models}/key-event/key-event.collection.js +0 -0
  109. /package/src/{v2/models → models}/key-event/key-event.model.js +0 -0
  110. /package/src/{v2/models → models}/key-event/key-event.schema.js +0 -0
  111. /package/src/{v2/models → models}/latest-audit/index.d.ts +0 -0
  112. /package/src/{v2/models → models}/latest-audit/index.js +0 -0
  113. /package/src/{v2/models → models}/latest-audit/latest-audit.collection.js +0 -0
  114. /package/src/{v2/models → models}/latest-audit/latest-audit.model.js +0 -0
  115. /package/src/{v2/models → models}/latest-audit/latest-audit.schema.js +0 -0
  116. /package/src/{v2/models → models}/opportunity/index.d.ts +0 -0
  117. /package/src/{v2/models → models}/opportunity/index.js +0 -0
  118. /package/src/{v2/models → models}/opportunity/opportunity.collection.js +0 -0
  119. /package/src/{v2/models → models}/opportunity/opportunity.model.js +0 -0
  120. /package/src/{v2/models → models}/opportunity/opportunity.schema.js +0 -0
  121. /package/src/{v2/models → models}/organization/index.d.ts +0 -0
  122. /package/src/{v2/models → models}/organization/index.js +0 -0
  123. /package/src/{v2/models → models}/organization/organization.collection.js +0 -0
  124. /package/src/{v2/models → models}/organization/organization.model.js +0 -0
  125. /package/src/{v2/models → models}/site/index.d.ts +0 -0
  126. /package/src/{v2/models → models}/site/index.js +0 -0
  127. /package/src/{v2/models → models}/site/site.collection.js +0 -0
  128. /package/src/{v2/models → models}/site/site.model.js +0 -0
  129. /package/src/{v2/models → models}/site-candidate/index.d.ts +0 -0
  130. /package/src/{v2/models → models}/site-candidate/index.js +0 -0
  131. /package/src/{v2/models → models}/site-candidate/site-candidate.collection.js +0 -0
  132. /package/src/{v2/models → models}/site-candidate/site-candidate.model.js +0 -0
  133. /package/src/{v2/models → models}/site-candidate/site-candidate.schema.js +0 -0
  134. /package/src/{v2/models → models}/site-top-page/index.d.ts +0 -0
  135. /package/src/{v2/models → models}/site-top-page/index.js +0 -0
  136. /package/src/{v2/models → models}/site-top-page/site-top-page.collection.js +0 -0
  137. /package/src/{v2/models → models}/site-top-page/site-top-page.model.js +0 -0
  138. /package/src/{v2/models → models}/site-top-page/site-top-page.schema.js +0 -0
  139. /package/src/{v2/models → models}/suggestion/index.d.ts +0 -0
  140. /package/src/{v2/models → models}/suggestion/index.js +0 -0
  141. /package/src/{v2/models → models}/suggestion/suggestion.collection.js +0 -0
  142. /package/src/{v2/models → models}/suggestion/suggestion.model.js +0 -0
  143. /package/src/{v2/models → models}/suggestion/suggestion.schema.js +0 -0
  144. /package/src/{v2/readme.md → readme.md} +0 -0
  145. /package/src/{v2/util → util}/accessor.utils.js +0 -0
  146. /package/src/{v2/util → util}/guards.d.ts +0 -0
  147. /package/src/{v2/util → util}/guards.js +0 -0
  148. /package/src/{v2/util → util}/index.d.ts +0 -0
  149. /package/src/{v2/util → util}/index.js +0 -0
  150. /package/src/{v2/util → util}/patcher.js +0 -0
  151. /package/src/{v2/util → util}/util.js +0 -0
@@ -1,115 +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, isValidUrl } from '@adobe/spacecat-shared-utils';
14
- import { Base } from '../base.js';
15
- import { ImportUrlStatus } from './import-constants.js';
16
-
17
- export const IMPORT_URL_EXPIRES_IN_DAYS = 30;
18
-
19
- /**
20
- * Creates a new ImportUrl object
21
- *
22
- * @param {Object} data
23
- * @returns {ImportUrl}
24
- */
25
- const ImportUrl = (data) => {
26
- const self = Base(data);
27
-
28
- self.getJobId = () => self.state.jobId;
29
- self.getUrl = () => self.state.url;
30
- self.getStatus = () => self.state.status;
31
- self.getReason = () => self.state.reason;
32
- // Absolute path to the resource that is being imported for the given URL
33
- self.getPath = () => self.state.path;
34
- // Resulting path and filename of the imported .docx file
35
- self.getFile = () => self.state.file;
36
- // Expiration date for the URL
37
- self.getExpiresAt = () => self.state.expiresAt;
38
-
39
- /**
40
- * Updates the state of the ImportJob.
41
- * @param key - The key to update.
42
- * @param value - The new value.
43
- * @param {Function} validator - An optional validation function to use before updating the value.
44
- * The validator can return false to indicate that the value isn't worth throwing an exception,
45
- * but continue to use the previous value.
46
- */
47
- const updateState = (key, value, validator) => {
48
- if (validator && typeof validator === 'function') {
49
- // a validator can return true or false to indicate if the value is valid
50
- // however if a validator throws an error, it is considered critical and invalid.
51
- if (!validator(value)) {
52
- return self;
53
- }
54
- }
55
-
56
- self.state[key] = value;
57
- self.touch();
58
-
59
- return self;
60
- };
61
-
62
- /**
63
- * Updates the status of the ImportUrl
64
- */
65
- self.setStatus = (status) => updateState('status', status, (value) => {
66
- if (!ImportUrlStatus[value]) {
67
- throw new Error(`Invalid Import URL status during update: ${value}`);
68
- }
69
- return true;
70
- });
71
-
72
- /**
73
- * Updates the reason that the import of this URL was not successful.
74
- */
75
- self.setReason = (reason) => updateState('reason', reason, hasText);
76
-
77
- /**
78
- * Updates the path of the ImportUrl
79
- */
80
- self.setPath = (path) => updateState('path', path, hasText);
81
-
82
- /**
83
- * Updates the file of the ImportUrl. This is the path and file name of the file which
84
- * was imported.
85
- */
86
- self.setFile = (file) => updateState('file', file, hasText);
87
-
88
- return Object.freeze(self);
89
- };
90
-
91
- /**
92
- * Creates a new ImportUrl object
93
- */
94
- export const createImportUrl = (data) => {
95
- const newState = { ...data };
96
-
97
- if (!isValidUrl(newState.url)) {
98
- throw new Error(`Invalid Url: ${newState.url}`);
99
- }
100
-
101
- if (!hasText(newState.jobId)) {
102
- throw new Error(`Invalid Job ID: ${newState.jobId}`);
103
- }
104
-
105
- if (!Object.values(ImportUrlStatus).includes(newState.status)) {
106
- throw new Error(`Invalid Import URL status: ${newState.status}`);
107
- }
108
-
109
- if (!newState.expiresAt) {
110
- newState.expiresAt = new Date();
111
- newState.expiresAt.setDate(newState.expiresAt.getDate() + IMPORT_URL_EXPIRES_IN_DAYS);
112
- }
113
-
114
- return ImportUrl(newState);
115
- };
@@ -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
- };
@@ -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
- };