@adobe/spacecat-shared-utils 1.70.1 → 1.72.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.72.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.71.0...@adobe/spacecat-shared-utils-v1.72.0) (2025-11-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * added interface correct definition ([#1114](https://github.com/adobe/spacecat-shared/issues/1114)) ([e377dab](https://github.com/adobe/spacecat-shared/commit/e377dabc263200e6c393ebf40c65e8c41fb134cb))
7
+
8
+ # [@adobe/spacecat-shared-utils-v1.71.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.70.1...@adobe/spacecat-shared-utils-v1.71.0) (2025-11-11)
9
+
10
+
11
+ ### Features
12
+
13
+ * added redirected url in broken-backlink ([#1111](https://github.com/adobe/spacecat-shared/issues/1111)) ([d0e1bd6](https://github.com/adobe/spacecat-shared/commit/d0e1bd619f8d2fe33807f58a23e54eac49b83708))
14
+
1
15
  # [@adobe/spacecat-shared-utils-v1.70.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.70.0...@adobe/spacecat-shared-utils-v1.70.1) (2025-11-08)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.70.1",
3
+ "version": "1.72.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.d.ts CHANGED
@@ -277,12 +277,12 @@ export function isoCalendarWeekMonday(date: Date): Date;
277
277
  * @param opts - Options object
278
278
  * @param opts.opportunity - The opportunity object
279
279
  * @param opts.suggestion - The suggestion object
280
- * @returns An array of extracted URLs
280
+ * @returns A promise that resolves to an array of extracted URLs
281
281
  */
282
282
  export function extractUrlsFromSuggestion(opts: {
283
283
  opportunity: any;
284
284
  suggestion: any;
285
- }): string[];
285
+ }): Promise<string[]>;
286
286
 
287
287
  /**
288
288
  * Extracts URLs from an opportunity based on the opportunity type.
@@ -10,13 +10,43 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import { context } from '@adobe/fetch';
13
14
  import { OPPORTUNITY_TYPES } from './constants.js';
14
15
 
16
+ const { fetch } = context();
17
+
18
+ /**
19
+ * Helper function to follow redirects and return the final URL
20
+ * @param {string} url - The URL to follow
21
+ * @returns {Promise<string>} - The final URL after following redirects
22
+ */
23
+ async function getFinalRedirectUrl(url) {
24
+ try {
25
+ const response = await fetch(url, {
26
+ method: 'HEAD',
27
+ redirect: 'follow',
28
+ });
29
+ return response.url;
30
+ } catch (error) {
31
+ // If HEAD fails, try GET
32
+ try {
33
+ const response = await fetch(url, {
34
+ method: 'GET',
35
+ redirect: 'follow',
36
+ });
37
+ return response.url;
38
+ } catch (getError) {
39
+ // If both fail, return the original URL
40
+ return url;
41
+ }
42
+ }
43
+ }
44
+
15
45
  /**
16
46
  * Function to extract the URL from a suggestion based on a particular type
17
47
  * @param {*} suggestion
18
48
  */
19
- function extractUrlsFromSuggestion(opts) {
49
+ async function extractUrlsFromSuggestion(opts) {
20
50
  const {
21
51
  opportunity,
22
52
  suggestion,
@@ -107,7 +137,8 @@ function extractUrlsFromSuggestion(opts) {
107
137
  {
108
138
  const url = data?.url_to;
109
139
  if (url && typeof url === 'string') {
110
- urls.push(url);
140
+ const finalUrl = await getFinalRedirectUrl(url);
141
+ urls.push(finalUrl);
111
142
  }
112
143
  }
113
144
  break;