@adobe/spacecat-shared-utils 1.32.0 → 1.33.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-utils-v1.33.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.33.0...@adobe/spacecat-shared-utils-v1.33.1) (2025-02-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([#622](https://github.com/adobe/spacecat-shared/issues/622)) ([6552a61](https://github.com/adobe/spacecat-shared/commit/6552a61ebd8b83c0a1dec51d50d44cf3b97819c1))
7
+
8
+ # [@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)
9
+
10
+
11
+ ### Features
12
+
13
+ * set default fetch user-agent ([#620](https://github.com/adobe/spacecat-shared/issues/620)) ([bd4b38c](https://github.com/adobe/spacecat-shared/commit/bd4b38c84ba4e85ec4d375a3e110de8845688d2a))
14
+
1
15
  # [@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)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.32.0",
3
+ "version": "1.33.1",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
@@ -45,10 +45,10 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@adobe/fetch": "4.1.11",
48
- "@aws-sdk/client-s3": "3.749.0",
49
- "@aws-sdk/client-sqs": "3.749.0",
48
+ "@aws-sdk/client-s3": "3.750.0",
49
+ "@aws-sdk/client-sqs": "3.750.0",
50
50
  "@json2csv/plainjs": "7.0.6",
51
51
  "aws-xray-sdk": "3.10.3",
52
- "uuid": "11.0.5"
52
+ "uuid": "11.1.0"
53
53
  }
54
54
  }
package/src/index.d.ts CHANGED
@@ -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
  }