@adobe/spacecat-shared-data-access 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.4.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.3.2...@adobe/spacecat-shared-data-access-v1.4.0) (2023-12-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * update audit config ([#63](https://github.com/adobe-rnd/spacecat-shared/issues/63)) ([00a468e](https://github.com/adobe-rnd/spacecat-shared/commit/00a468e9404676212ec9441c8a7fccf1a93c636f))
7
+
1
8
  # [@adobe/spacecat-shared-data-access-v1.3.2](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.3.1...@adobe/spacecat-shared-data-access-v1.3.2) (2023-12-16)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -12,66 +12,185 @@
12
12
 
13
13
  // TODO: introduce AuditType interface or Scores interface
14
14
 
15
+ /**
16
+ * Represents an individual audit of a site.
17
+ */
15
18
  export interface Audit {
19
+ /**
20
+ * Retrieves the site ID associated with this audit.
21
+ * @returns {string} The site ID.
22
+ */
16
23
  getSiteId: () => string;
24
+
25
+ /**
26
+ * Retrieves the timestamp when the audit was performed.
27
+ * @returns {string} The audit timestamp.
28
+ */
17
29
  getAuditedAt: () => string;
30
+
31
+ /**
32
+ * Retrieves the result of the audit.
33
+ * @returns {object} The audit result.
34
+ */
18
35
  getAuditResult: () => object;
36
+
37
+ /**
38
+ * Retrieves the type of the audit.
39
+ * @returns {object} The audit type.
40
+ */
19
41
  getAuditType: () => object;
42
+
43
+ /**
44
+ * Retrieves the expiration date of the audit.
45
+ * @returns {Date} The expiration date.
46
+ */
20
47
  getExpiresAt: () => Date;
48
+
49
+ /**
50
+ * Retrieves a reference to the full audit.
51
+ * @returns {string} The full audit reference.
52
+ */
21
53
  getFullAuditRef: () => string;
54
+
55
+ /**
56
+ * Indicates whether the audit is live.
57
+ * @returns {boolean} True if the audit is live, false otherwise.
58
+ */
22
59
  isLive: () => boolean;
60
+
61
+ /**
62
+ * Indicates whether there was an error in the audit.
63
+ * @returns {boolean} True if there was an error, false otherwise.
64
+ */
23
65
  isError: () => boolean;
66
+
67
+ /**
68
+ * Retrieves the scores from the audit.
69
+ * @returns {object} The audit scores.
70
+ */
24
71
  getScores: () => object;
25
72
  }
26
73
 
27
74
  /**
28
- * AuditConfigType defines the structure for specific audit type configurations
75
+ * AuditConfigType defines the structure for specific audit type configurations.
29
76
  */
30
77
  export interface AuditConfigType {
31
78
  /**
32
79
  * Returns true if the audit type is disabled for the site. If an audit type is disabled, no
33
80
  * audits of that type will be scheduled for the site.
34
- * @returns True if the audit type is disabled for the site
81
+ * @returns {boolean} True if the audit type is disabled for the site.
35
82
  */
36
- disabled(): boolean;
83
+ disabled: () => boolean;
37
84
  }
38
85
 
39
86
  /**
40
- * AuditConfig defines the structure for the overall audit configuration of a site
87
+ * AuditConfig defines the structure for the overall audit configuration of a site.
41
88
  */
42
89
  export interface AuditConfig {
43
90
  /**
44
91
  * Returns true if audits are disabled for the site. If audits are disabled, no audits will be
45
92
  * scheduled for the site. Overrides any audit type specific configurations.
46
- * @returns True if audits are disabled for the site
93
+ * @returns {boolean} True if audits are disabled for the site.
47
94
  */
48
95
  auditsDisabled: () => boolean;
96
+
49
97
  /**
50
98
  * Returns the audit config for a specific audit type. The audit type is the key.
51
- * @param auditType The audit type to get the config for
52
- * @returns The audit config for the audit type
99
+ * @param {string} auditType The audit type to get the config for.
100
+ * @returns {AuditConfigType} The audit config for the audit type.
53
101
  */
54
102
  getAuditTypeConfig: (auditType: string) => AuditConfigType;
103
+
55
104
  /**
56
105
  * Returns the audit configs for all audit types. The keys are the audit types.
57
- * @returns The audit configs for all audit types
106
+ * @returns {object} The audit configs for all audit types.
58
107
  */
59
108
  getAuditTypeConfigs: () => object;
60
109
  }
61
110
 
111
+ /**
112
+ * Represents a site with associated audit and configuration data.
113
+ */
62
114
  export interface Site {
115
+ /**
116
+ * Retrieves the ID of the site.
117
+ * @returns {string} The site ID.
118
+ */
63
119
  getId: () => string;
120
+
121
+ /**
122
+ * Retrieves the base URL of the site.
123
+ * @returns {string} The base URL.
124
+ */
64
125
  getBaseURL: () => string;
126
+
127
+ /**
128
+ * Retrieves the GitHub URL associated with the site.
129
+ * @returns {string} The GitHub URL.
130
+ */
65
131
  getGitHubURL: () => string;
132
+
133
+ /**
134
+ * Retrieves the IMS Organization ID associated with the site.
135
+ * @returns {string} The IMS Org ID.
136
+ */
66
137
  getImsOrgId: () => string;
138
+
139
+ /**
140
+ * Retrieves the creation timestamp of the site.
141
+ * @returns {string} The creation timestamp.
142
+ */
67
143
  getCreatedAt: () => string;
144
+
145
+ /**
146
+ * Retrieves the last update timestamp of the site.
147
+ * @returns {string} The last update timestamp.
148
+ */
68
149
  getUpdatedAt: () => string;
150
+
151
+ /**
152
+ * Retrieves the current audit configuration for the site.
153
+ * @returns {AuditConfig} The current audit configuration.
154
+ */
69
155
  getAuditConfig: () => AuditConfig;
156
+
157
+ /**
158
+ * Retrieves the audits associated with the site.
159
+ * @returns {Audit[]} The list of audits.
160
+ */
70
161
  getAudits: () => Audit[];
162
+
163
+ /**
164
+ * Indicates whether the site is live.
165
+ * @returns {boolean} True if the site is live, false otherwise.
166
+ */
71
167
  isLive: () => boolean;
168
+
169
+ /**
170
+ * Updates the list of audits for the site.
171
+ * @param {Audit[]} audits The new list of audits.
172
+ * @returns {Site} The updated site instance.
173
+ */
72
174
  setAudits: (audits: Audit[]) => Site;
175
+
176
+ /**
177
+ * Toggles the live status of the site.
178
+ * @returns {Site} The updated site instance with the toggled live status.
179
+ */
73
180
  toggleLive: () => Site;
181
+
182
+ /**
183
+ * Updates the GitHub URL of the site.
184
+ * @param {string} gitHubURL The new GitHub URL.
185
+ * @returns {Site} The updated site instance.
186
+ */
74
187
  updateGitHubURL: (gitHubURL: string) => Site;
188
+
189
+ /**
190
+ * Updates the IMS Org ID of the site.
191
+ * @param {string} imsOrgId The new IMS Org ID.
192
+ * @returns {Site} The updated site instance.
193
+ */
75
194
  updateImsOrgId: (imsOrgId: string) => Site;
76
195
  }
77
196
 
@@ -10,9 +10,21 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- const AuditConfigType = (data = {}, allAuditsDisabled = false) => ({
14
- disabled: () => allAuditsDisabled || data.disabled || false,
15
- });
13
+ const AuditConfigType = (data = {}) => {
14
+ const state = {
15
+ disabled: data.disabled || false,
16
+ };
17
+
18
+ const self = {
19
+ disabled: () => state.disabled,
20
+
21
+ updateDisabled: (newValue) => {
22
+ state.disabled = newValue;
23
+ },
24
+ };
25
+
26
+ return Object.freeze(self);
27
+ };
16
28
 
17
29
  AuditConfigType.fromDynamoItem = (dynamoItem) => {
18
30
  const auditConfigTypeData = {
@@ -9,14 +9,9 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+
12
13
  import AuditConfigType from './audit-config-type.js';
13
14
 
14
- /**
15
- * Initializes the audit type configs. If auditsDisabled is true, all audit types will be disabled.
16
- * @param {object} auditTypeConfigs - Object containing audit type configs.
17
- * @param {boolean} auditsDisabled - Flag indicating if all audits are disabled.
18
- * @return {object} Object containing audit type configs.
19
- */
20
15
  function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) {
21
16
  return Object.entries(auditTypeConfigs || {}).reduce((acc, [key, value]) => {
22
17
  acc[key] = AuditConfigType(value, auditsDisabled);
@@ -25,12 +20,24 @@ function getAuditTypeConfigs(auditTypeConfigs, auditsDisabled) {
25
20
  }
26
21
 
27
22
  const AuditConfig = (data = {}) => {
28
- const auditTypeConfigs = getAuditTypeConfigs(data.auditTypeConfigs, data.auditsDisabled);
29
- return {
30
- auditsDisabled: () => data.auditsDisabled || false,
31
- getAuditTypeConfigs: () => auditTypeConfigs,
32
- getAuditTypeConfig: (type) => auditTypeConfigs[type],
23
+ const state = {
24
+ auditsDisabled: data.auditsDisabled || false,
25
+ auditTypeConfigs: getAuditTypeConfigs(data.auditTypeConfigs, data.auditsDisabled),
33
26
  };
27
+
28
+ const self = {
29
+ auditsDisabled: () => state.auditsDisabled,
30
+ getAuditTypeConfigs: () => state.auditTypeConfigs,
31
+ getAuditTypeConfig: (type) => state.auditTypeConfigs[type],
32
+ updateAuditsDisabled: (newValue) => {
33
+ state.auditsDisabled = newValue;
34
+ },
35
+ updateAuditTypeConfig: (type, config) => {
36
+ state.auditTypeConfigs[type] = AuditConfigType(config);
37
+ },
38
+ };
39
+
40
+ return Object.freeze(self);
34
41
  };
35
42
 
36
43
  AuditConfig.fromDynamoItem = (dynamoItem) => AuditConfig(dynamoItem);
@@ -68,6 +68,18 @@ const Site = (data = {}) => {
68
68
  return self;
69
69
  }; */
70
70
 
71
+ self.setAllAuditsDisabled = (disabled) => {
72
+ self.state.auditConfig.updateAuditsDisabled(disabled);
73
+ self.touch();
74
+ return self;
75
+ };
76
+
77
+ self.updateAuditTypeConfig = (type, config) => {
78
+ self.state.auditConfig.updateAuditTypeConfig(type, config);
79
+ self.touch();
80
+ return self;
81
+ };
82
+
71
83
  /**
72
84
  * Updates the GitHub URL belonging to the site.
73
85
  * @param {string} gitHubURL - The GitHub URL.