@adobe/spacecat-shared-utils 1.31.1 → 1.33.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-utils-v1.33.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.32.0...@adobe/spacecat-shared-utils-v1.33.0) (2025-02-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * set default fetch user-agent ([#620](https://github.com/adobe/spacecat-shared/issues/620)) ([bd4b38c](https://github.com/adobe/spacecat-shared/commit/bd4b38c84ba4e85ec4d375a3e110de8845688d2a))
7
+
8
+ # [@adobe/spacecat-shared-utils-v1.32.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.31.1...@adobe/spacecat-shared-utils-v1.32.0) (2025-02-17)
9
+
10
+
11
+ ### Features
12
+
13
+ * introduce fetch config for site to use custom headers ([#585](https://github.com/adobe/spacecat-shared/issues/585)) ([10a2892](https://github.com/adobe/spacecat-shared/commit/10a28928c3946ea05c4644f16971ccff8d43e994))
14
+
1
15
  # [@adobe/spacecat-shared-utils-v1.31.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.31.0...@adobe/spacecat-shared-utils-v1.31.1) (2025-02-16)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.31.1",
3
+ "version": "1.33.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.d.ts CHANGED
@@ -103,7 +103,7 @@ declare function composeBaseURL(domain: string): string;
103
103
  * @param {string} [userAgent] - Optional user agent to use in the audit URL.
104
104
  * @returns a promise that resolves the composed audit URL.
105
105
  */
106
- declare function composeAuditURL(url: string, userAgent: string): Promise<string>;
106
+ declare function composeAuditURL(url: string, userAgent?: string): Promise<string>;
107
107
 
108
108
  /**
109
109
  * Resolves the name of the secret based on the function version.
@@ -242,3 +242,5 @@ export function s3Wrapper(fn: (request: object, context: object) => Promise<Resp
242
242
  export function fetch(url: string | Request, options?: RequestOptions): Promise<Response>;
243
243
 
244
244
  export function tracingFetch(url: string | Request, options?: RequestOptions): Promise<Response>;
245
+
246
+ export const SPACECAT_USER_AGENT: string;
package/src/index.js CHANGED
@@ -60,5 +60,5 @@ export { getStoredMetrics, storeMetrics } from './metrics-store.js';
60
60
  export { s3Wrapper } from './s3.js';
61
61
 
62
62
  export { fetch } from './adobe-fetch.js';
63
- export { tracingFetch } from './tracing-fetch.js';
63
+ export { tracingFetch, SPACECAT_USER_AGENT } from './tracing-fetch.js';
64
64
  export { getHighFormViewsLowConversionMetrics, getHighPageViewsLowFormViewsMetrics, getHighPageViewsLowFormCtrMetrics } from './formcalc.js';
@@ -13,7 +13,9 @@ import { Request } from '@adobe/fetch';
13
13
  import AWSXRay from 'aws-xray-sdk';
14
14
 
15
15
  import { fetch as adobeFetch } from './adobe-fetch.js';
16
- import { isNumber } from './functions.js';
16
+ import { isNumber, isObject } from './functions.js';
17
+
18
+ export const SPACECAT_USER_AGENT = 'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36 Spacecat/1.0';
17
19
 
18
20
  /**
19
21
  * Creates a subsegment for a given hostname based on whether the parent segment is traced or not.
@@ -114,6 +116,21 @@ const handleSubSegmentError = (subSegment, request, error) => {
114
116
  export async function tracingFetch(url, options) {
115
117
  const parentSegment = AWSXRay.getSegment();
116
118
 
119
+ options = isObject(options) ? options : {};
120
+ options.headers = isObject(options.headers) ? options.headers : new Headers();
121
+
122
+ // find user-agent header in headers case insensitively
123
+ let hasUserAgent = false;
124
+ Object.keys(options.headers).forEach((key) => {
125
+ if (key.toLowerCase() === 'user-agent') {
126
+ hasUserAgent = true;
127
+ }
128
+ });
129
+
130
+ if (!hasUserAgent) {
131
+ options.headers['User-Agent'] = SPACECAT_USER_AGENT;
132
+ }
133
+
117
134
  if (!parentSegment) {
118
135
  return adobeFetch(url, options);
119
136
  }