@adobe/spacecat-shared-data-access 2.6.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,10 @@
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
+
1
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)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -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
  }