@adobe/spacecat-shared-data-access 2.5.0 → 2.7.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,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v2.7.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.6.0...@adobe/spacecat-shared-data-access-v2.7.0) (2025-02-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Implement dependency check for handlers ([#608](https://github.com/adobe/spacecat-shared/issues/608)) ([0ada515](https://github.com/adobe/spacecat-shared/commit/0ada5157a3cf50bf67129e296e719a14ee2c451c)), closes [/github.com/adobe/spacecat-shared/blob/main/packages/spacecat-shared-data-access/src/models/configuration/configuration.schema.js#L35-L39](https://github.com//github.com/adobe/spacecat-shared/blob/main/packages/spacecat-shared-data-access/src/models/configuration/configuration.schema.js/issues/L35-L39)
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v2.6.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.5.0...@adobe/spacecat-shared-data-access-v2.6.0) (2025-02-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **latest-metrics:** add latest metrics handling to config ([#607](https://github.com/adobe/spacecat-shared/issues/607)) ([0233958](https://github.com/adobe/spacecat-shared/commit/0233958f782e1cef24cc3df3c7445520697c1efa))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v2.5.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.4.0...@adobe/spacecat-shared-data-access-v2.5.0) (2025-02-18)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { isNonEmptyObject } from '@adobe/spacecat-shared-utils';
|
|
13
|
+
import { isNonEmptyObject, isNonEmptyArray } from '@adobe/spacecat-shared-utils';
|
|
14
14
|
|
|
15
15
|
import { sanitizeIdAndAuditFields } from '../../util/util.js';
|
|
16
16
|
import BaseModel from '../base/base.model.js';
|
|
@@ -146,12 +146,58 @@ class Configuration extends BaseModel {
|
|
|
146
146
|
const siteId = site.getId();
|
|
147
147
|
if (this.isHandlerEnabledForSite(type, site)) return;
|
|
148
148
|
|
|
149
|
+
const deps = this.isHandlerDependencyMetForSite(type, site);
|
|
150
|
+
if (deps !== true) {
|
|
151
|
+
throw new Error(`Cannot enable handler ${type} for site ${siteId} because of missing dependencies: ${deps}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
149
154
|
this.updateHandlerSites(type, siteId, true);
|
|
150
155
|
}
|
|
151
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Check if all dependencies for a handler of given type are met for the given org.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} type handler type
|
|
161
|
+
* @param {object} org org object
|
|
162
|
+
* @returns true if all dependencies are met, array with missing dependencies otherwise
|
|
163
|
+
*/
|
|
164
|
+
isHandlerDependencyMetForOrg(type, org) {
|
|
165
|
+
const handler = this.getHandler(type);
|
|
166
|
+
|
|
167
|
+
if (!handler || !isNonEmptyArray(handler?.dependencies)) return true;
|
|
168
|
+
|
|
169
|
+
const unmetDependencies = handler.dependencies
|
|
170
|
+
.filter(({ handler: depHandler }) => !this.isHandlerEnabledForOrg(depHandler, org))
|
|
171
|
+
.map(({ handler: depHandler }) => depHandler);
|
|
172
|
+
|
|
173
|
+
return isNonEmptyArray(unmetDependencies) ? unmetDependencies : true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Check if all dependencies for a handler of given type are met for the given site.
|
|
178
|
+
*
|
|
179
|
+
* @param {string} type handler type
|
|
180
|
+
* @param {object} site site object
|
|
181
|
+
* @returns true if all dependencies are met, array with missing dependencies otherwise
|
|
182
|
+
*/
|
|
183
|
+
isHandlerDependencyMetForSite(type, site) {
|
|
184
|
+
const handler = this.getHandler(type);
|
|
185
|
+
if (!handler || !isNonEmptyArray(handler?.dependencies)) return true;
|
|
186
|
+
|
|
187
|
+
const unmetDependencies = handler.dependencies
|
|
188
|
+
.filter(({ handler: depHandler }) => !this.isHandlerEnabledForSite(depHandler, site))
|
|
189
|
+
.map(({ handler: depHandler }) => depHandler);
|
|
190
|
+
|
|
191
|
+
return isNonEmptyArray(unmetDependencies) ? unmetDependencies : true;
|
|
192
|
+
}
|
|
193
|
+
|
|
152
194
|
enableHandlerForOrg(type, org) {
|
|
153
195
|
const orgId = org.getId();
|
|
154
196
|
if (this.isHandlerEnabledForOrg(type, org)) return;
|
|
197
|
+
const deps = this.isHandlerDependencyMetForOrg(type, org);
|
|
198
|
+
if (deps !== true) {
|
|
199
|
+
throw new Error(`Cannot enable handler ${type} for org ${orgId} because of missing dependencies: ${deps}`);
|
|
200
|
+
}
|
|
155
201
|
|
|
156
202
|
this.updateHandlerOrgs(type, orgId, true);
|
|
157
203
|
}
|
|
@@ -38,6 +38,11 @@ export const configSchema = Joi.object({
|
|
|
38
38
|
name: Joi.string(),
|
|
39
39
|
pattern: Joi.string(),
|
|
40
40
|
})).optional(),
|
|
41
|
+
latestMetrics: Joi.object({
|
|
42
|
+
pageViewsChange: Joi.number(),
|
|
43
|
+
ctrChange: Joi.number(),
|
|
44
|
+
projectedTrafficValue: Joi.number(),
|
|
45
|
+
}),
|
|
41
46
|
}).unknown(true)).unknown(true),
|
|
42
47
|
}).unknown(true);
|
|
43
48
|
|
|
@@ -73,6 +78,7 @@ export const Config = (data = {}) => {
|
|
|
73
78
|
self.getFixedURLs = (type) => state?.handlers?.[type]?.fixedURLs;
|
|
74
79
|
self.getIncludedURLs = (type) => state?.handlers?.[type]?.includedURLs;
|
|
75
80
|
self.getGroupedURLs = (type) => state?.handlers?.[type]?.groupedURLs;
|
|
81
|
+
self.getLatestMetrics = (type) => state?.handlers?.[type]?.latestMetrics;
|
|
76
82
|
self.getFetchConfig = () => state?.fetchConfig;
|
|
77
83
|
|
|
78
84
|
self.updateSlackConfig = (channel, workspace, invitedUserCount) => {
|
|
@@ -120,6 +126,12 @@ export const Config = (data = {}) => {
|
|
|
120
126
|
validateConfiguration(state);
|
|
121
127
|
};
|
|
122
128
|
|
|
129
|
+
self.updateLatestMetrics = (type, latestMetrics) => {
|
|
130
|
+
state.handlers = state.handlers || {};
|
|
131
|
+
state.handlers[type] = state.handlers[type] || {};
|
|
132
|
+
state.handlers[type].latestMetrics = latestMetrics;
|
|
133
|
+
};
|
|
134
|
+
|
|
123
135
|
self.updateFetchConfig = (fetchConfig) => {
|
|
124
136
|
state.fetchConfig = fetchConfig;
|
|
125
137
|
};
|