@adobe/spacecat-shared-data-access 2.34.0 → 2.35.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.35.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.34.1...@adobe/spacecat-shared-data-access-v2.35.0) (2025-07-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * introduce isSandbox flag for sandbox sites ([#842](https://github.com/adobe/spacecat-shared/issues/842)) ([066adb4](https://github.com/adobe/spacecat-shared/commit/066adb4629901a82b7c5c21297795d82eb771d29))
7
+
8
+ # [@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)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * 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))
14
+
1
15
  # [@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
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "2.34.0",
3
+ "version": "2.35.0",
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',
@@ -257,7 +258,20 @@ export function validateConfiguration(config) {
257
258
  }
258
259
 
259
260
  export const Config = (data = {}) => {
260
- 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
+ }
261
275
 
262
276
  const state = { ...validConfig };
263
277
  const self = { state };
@@ -137,6 +137,7 @@ export interface Site extends BaseModel {
137
137
  getHlxConfig(): HlxConfig;
138
138
  getDeliveryConfig(): object;
139
139
  getIsLive(): boolean;
140
+ getIsSandbox(): boolean;
140
141
  getIsLiveToggledAt(): string;
141
142
  getKeyEvents(): Promise<KeyEvent[]>
142
143
  getKeyEventsByTimestamp(timestamp: string): Promise<KeyEvent[]>
@@ -164,6 +165,7 @@ export interface Site extends BaseModel {
164
165
  setHlxConfig(hlxConfig: HlxConfig): Site;
165
166
  setDeliveryConfig(deliveryConfig: object): Site;
166
167
  setIsLive(isLive: boolean): Site;
168
+ setIsSandbox(isSandbox: boolean): Site;
167
169
  setIsLiveToggledAt(isLiveToggledAt: string): Site;
168
170
  setOrganizationId(organizationId: string): Site;
169
171
  toggleLive(): Site;
@@ -87,6 +87,10 @@ const schema = new SchemaBuilder(Site, SiteCollection)
87
87
  default: {},
88
88
  validate: (value) => isObject(value),
89
89
  })
90
+ .addAttribute('isSandbox', {
91
+ type: 'boolean',
92
+ default: false,
93
+ })
90
94
  .addAttribute('isLive', {
91
95
  type: 'boolean',
92
96
  required: true,
@@ -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
+ }