@adobe/spacecat-shared-data-access 2.34.0 → 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 +7 -0
- package/package.json +1 -1
- package/src/models/site/config.js +15 -1
- package/src/service/index.js +3 -0
- package/src/util/index.js +5 -0
- package/src/util/logger-registry.js +50 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
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)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -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',
|
|
@@ -257,7 +258,20 @@ export function validateConfiguration(config) {
|
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
export const Config = (data = {}) => {
|
|
260
|
-
|
|
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
|
+
}
|
|
261
275
|
|
|
262
276
|
const state = { ...validConfig };
|
|
263
277
|
const self = { state };
|
package/src/service/index.js
CHANGED
|
@@ -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
|
@@ -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
|
+
}
|