@adobe/spacecat-shared-data-access 2.9.4 → 2.9.5

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.9.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.9.4...@adobe/spacecat-shared-data-access-v2.9.5) (2025-02-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **override-base-url:** add overrideBaseURL in site.config.fetchConfig ([#633](https://github.com/adobe/spacecat-shared/issues/633)) ([526874f](https://github.com/adobe/spacecat-shared/commit/526874f8665e7bae94ca8968f1cb834cd424ae9f))
7
+
1
8
  # [@adobe/spacecat-shared-data-access-v2.9.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.9.3...@adobe/spacecat-shared-data-access-v2.9.4) (2025-02-27)
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.9.4",
3
+ "version": "2.9.5",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -34,7 +34,7 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@adobe/spacecat-shared-utils": "1.26.4",
37
+ "@adobe/spacecat-shared-utils": "1.33.1",
38
38
  "@aws-sdk/client-dynamodb": "3.751.0",
39
39
  "@aws-sdk/lib-dynamodb": "3.751.0",
40
40
  "@types/joi": "17.2.3",
@@ -48,6 +48,7 @@
48
48
  "chai": "5.2.0",
49
49
  "chai-as-promised": "8.0.1",
50
50
  "dynamo-db-local": "9.4.0",
51
+ "nock": "14.0.1",
51
52
  "sinon": "19.0.2",
52
53
  "sinon-chai": "4.0.0"
53
54
  }
@@ -39,8 +39,10 @@ export const IMPORT_TYPE_SCHEMAS = {
39
39
  [IMPORT_TYPES.ORGANIC_KEYWORDS]: Joi.object({
40
40
  type: Joi.string().valid(IMPORT_TYPES.ORGANIC_KEYWORDS).required(),
41
41
  ...IMPORT_BASE_KEYS,
42
- limit: Joi.number().integer().min(1).max(100),
43
- pageUrl: Joi.string().uri(),
42
+ geo: Joi.string().optional(),
43
+ limit: Joi.number().integer().min(1).max(100)
44
+ .optional(),
45
+ pageUrl: Joi.string().uri().optional(),
44
46
  }),
45
47
  [IMPORT_TYPES.ORGANIC_TRAFFIC]: Joi.object({
46
48
  type: Joi.string().valid(IMPORT_TYPES.ORGANIC_TRAFFIC).required(),
@@ -49,7 +51,9 @@ export const IMPORT_TYPE_SCHEMAS = {
49
51
  [IMPORT_TYPES.TOP_PAGES]: Joi.object({
50
52
  type: Joi.string().valid(IMPORT_TYPES.TOP_PAGES).required(),
51
53
  ...IMPORT_BASE_KEYS,
52
- geo: Joi.string(),
54
+ geo: Joi.string().optional(),
55
+ limit: Joi.number().integer().min(1).max(2000)
56
+ .optional(),
53
57
  }),
54
58
  };
55
59
 
@@ -86,6 +90,7 @@ export const configSchema = Joi.object({
86
90
  ),
87
91
  fetchConfig: Joi.object({
88
92
  headers: Joi.object().pattern(Joi.string(), Joi.string()),
93
+ overrideBaseURL: Joi.string().uri().optional(),
89
94
  }).optional(),
90
95
  handlers: Joi.object().pattern(Joi.string(), Joi.object({
91
96
  mentions: Joi.object().pattern(Joi.string(), Joi.array().items(Joi.string())),
@@ -49,6 +49,7 @@ export interface ImportConfig {
49
49
  enabled: boolean;
50
50
  pageUrl?: string;
51
51
  geo?: string;
52
+ limit?: number;
52
53
  }
53
54
 
54
55
  export interface SiteConfig {
@@ -83,6 +84,7 @@ export interface SiteConfig {
83
84
  }>;
84
85
  fetchConfig?: {
85
86
  headers?: Record<string, string>;
87
+ overrideBaseURL?: string;
86
88
  };
87
89
  };
88
90
  getSlackConfig(): { workspace?: string; channel?: string; invitedUserCount?: number };
@@ -102,7 +104,7 @@ export interface SiteConfig {
102
104
  getGroupedURLs(type: string): Array<{ name: string; pattern: string }> | undefined;
103
105
  getLatestMetrics(type: string):
104
106
  { pageViewsChange: number; ctrChange: number; projectedTrafficValue: number } | undefined;
105
- getFetchConfig(): { headers?: Record<string, string> } | undefined;
107
+ getFetchConfig(): { headers?: Record<string, string>, overrideBaseURL?: string } | undefined;
106
108
  }
107
109
 
108
110
  export interface Site extends BaseModel {
@@ -10,6 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import { composeAuditURL, hasText, isValidUrl } from '@adobe/spacecat-shared-utils';
13
14
  import BaseModel from '../base/base.model.js';
14
15
 
15
16
  /**
@@ -32,6 +33,32 @@ class Site extends BaseModel {
32
33
  this.setIsLive(newIsLive);
33
34
  return this;
34
35
  }
36
+
37
+ /**
38
+ * Resolves the site's base URL to a final URL by fetching the URL,
39
+ * following the redirects and returning the final URL.
40
+ *
41
+ * If the site has a configured overrideBaseURL, that one will be returned.
42
+ * Otherwise, the site's base URL will be used.
43
+ *
44
+ * If the site has a configured User-Agent, it will be used to resolve the URL.
45
+ *
46
+ * @returns a promise that resolves the final URL.
47
+ * @throws {Error} if the final URL cannot be resolved.
48
+ */
49
+ async resolveFinalURL() {
50
+ const overrideBaseURL = this.getConfig()?.getFetchConfig()?.overrideBaseURL;
51
+ if (isValidUrl(overrideBaseURL)) {
52
+ return overrideBaseURL.replace(/^https?:\/\//, '');
53
+ }
54
+
55
+ const userAgentConfigured = this.getConfig()?.getFetchConfig()?.headers?.['User-Agent'];
56
+ if (hasText(userAgentConfigured)) {
57
+ return composeAuditURL(this.getBaseURL(), userAgentConfigured);
58
+ }
59
+
60
+ return composeAuditURL(this.getBaseURL());
61
+ }
35
62
  }
36
63
 
37
64
  export default Site;