@adobe/spacecat-shared-data-access 2.33.6 → 2.34.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v2.34.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.34.0...@adobe/spacecat-shared-data-access-v2.34.1) (2025-07-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add try catch for config for sites validation ([#850](https://github.com/adobe/spacecat-shared/issues/850)) ([17c8402](https://github.com/adobe/spacecat-shared/commit/17c84023568de20395ba52a6876683f1354ba6b7))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v2.34.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.33.6...@adobe/spacecat-shared-data-access-v2.34.0) (2025-07-14)
9
+
10
+
11
+ ### Features
12
+
13
+ * add traffic analysis import handler ([#846](https://github.com/adobe/spacecat-shared/issues/846)) ([c8b65f0](https://github.com/adobe/spacecat-shared/commit/c8b65f0b0a29afdafc84686cf8b2ff1f6f9ed9cb))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v2.33.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.33.5...@adobe/spacecat-shared-data-access-v2.33.6) (2025-07-12)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "2.33.6",
3
+ "version": "2.34.1",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import Joi from 'joi';
14
+ import { getLogger } from '../../util/logger-registry.js';
14
15
 
15
16
  export const IMPORT_TYPES = {
16
17
  ORGANIC_KEYWORDS: 'organic-keywords',
@@ -23,6 +24,7 @@ export const IMPORT_TYPES = {
23
24
  ALL_TRAFFIC: 'all-traffic',
24
25
  CWV_DAILY: 'cwv-daily',
25
26
  CWV_WEEKLY: 'cwv-weekly',
27
+ TRAFFIC_ANALYSIS: 'traffic-analysis',
26
28
  };
27
29
 
28
30
  export const IMPORT_DESTINATIONS = {
@@ -104,6 +106,12 @@ export const IMPORT_TYPE_SCHEMAS = {
104
106
  type: Joi.string().valid(IMPORT_TYPES.CWV_WEEKLY).required(),
105
107
  ...IMPORT_BASE_KEYS,
106
108
  }),
109
+ [IMPORT_TYPES.TRAFFIC_ANALYSIS]: Joi.object({
110
+ type: Joi.string().valid(IMPORT_TYPES.TRAFFIC_ANALYSIS).required(),
111
+ year: Joi.number().integer().optional(),
112
+ week: Joi.number().integer().optional(),
113
+ ...IMPORT_BASE_KEYS,
114
+ }),
107
115
  };
108
116
 
109
117
  export const DEFAULT_IMPORT_CONFIGS = {
@@ -168,6 +176,12 @@ export const DEFAULT_IMPORT_CONFIGS = {
168
176
  sources: ['rum'],
169
177
  enabled: true,
170
178
  },
179
+ 'traffic-analysis': {
180
+ type: 'traffic-analysis',
181
+ destinations: ['default'],
182
+ sources: ['rum'],
183
+ enabled: true,
184
+ },
171
185
  };
172
186
 
173
187
  export const configSchema = Joi.object({
@@ -244,7 +258,20 @@ export function validateConfiguration(config) {
244
258
  }
245
259
 
246
260
  export const Config = (data = {}) => {
247
- const validConfig = validateConfiguration(data);
261
+ let validConfig;
262
+
263
+ try {
264
+ validConfig = validateConfiguration(data);
265
+ } catch (error) {
266
+ const logger = getLogger();
267
+ if (logger && logger !== console) {
268
+ logger.error('Site configuration validation failed, using default config', {
269
+ error: error.message,
270
+ invalidConfig: data,
271
+ });
272
+ }
273
+ validConfig = { ...DEFAULT_CONFIG };
274
+ }
248
275
 
249
276
  const state = { ...validConfig };
250
277
  const self = { state };
@@ -16,6 +16,7 @@ import { Service } from 'electrodb';
16
16
 
17
17
  import { instrumentAWSClient } from '@adobe/spacecat-shared-utils';
18
18
  import { EntityRegistry } from '../models/index.js';
19
+ import { registerLogger } from '../util/logger-registry.js';
19
20
 
20
21
  export * from '../errors/index.js';
21
22
  export * from '../models/index.js';
@@ -58,6 +59,8 @@ const createElectroService = (client, config, log) => {
58
59
  * @returns {object} Data access collections for interacting with entities
59
60
  */
60
61
  export const createDataAccess = (config, log = console, client = undefined) => {
62
+ registerLogger(log);
63
+
61
64
  const rawClient = createRawClient(client);
62
65
  const electroService = createElectroService(rawClient, config, log);
63
66
  const entityRegistry = new EntityRegistry(electroService, log);
package/src/util/index.js CHANGED
@@ -21,3 +21,8 @@ export {
21
21
  guardSet,
22
22
  guardString,
23
23
  } from './guards.js';
24
+
25
+ export {
26
+ registerLogger,
27
+ getLogger,
28
+ } from './logger-registry.js';
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright 2025 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
+ class LoggerRegistry {
14
+ static #instance = null;
15
+
16
+ #logger = null;
17
+
18
+ static getInstance() {
19
+ if (!LoggerRegistry.#instance) {
20
+ LoggerRegistry.#instance = new LoggerRegistry();
21
+ }
22
+ return LoggerRegistry.#instance;
23
+ }
24
+
25
+ setLogger(logger) {
26
+ this.#logger = logger;
27
+ }
28
+
29
+ getLogger() {
30
+ return this.#logger || console;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Registers a logger instance for global access.
36
+ * This should be called during data access initialization.
37
+ * @param {Object} logger - Logger instance
38
+ */
39
+ export function registerLogger(logger) {
40
+ LoggerRegistry.getInstance().setLogger(logger);
41
+ }
42
+
43
+ /**
44
+ * Gets the currently registered logger instance.
45
+ * Falls back to console if no logger is registered.
46
+ * @returns {Object} Logger instance
47
+ */
48
+ export function getLogger() {
49
+ return LoggerRegistry.getInstance().getLogger();
50
+ }