@adobe/spacecat-shared-utils 1.70.0 → 1.71.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 +14 -0
- package/package.json +3 -3
- package/src/url-extractors.js +33 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@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)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added redirected url in broken-backlink ([#1111](https://github.com/adobe/spacecat-shared/issues/1111)) ([d0e1bd6](https://github.com/adobe/spacecat-shared/commit/d0e1bd619f8d2fe33807f58a23e54eac49b83708))
|
|
7
|
+
|
|
8
|
+
# [@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)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update external fixes ([#1107](https://github.com/adobe/spacecat-shared/issues/1107)) ([f4cdb50](https://github.com/adobe/spacecat-shared/commit/f4cdb50f96d18dd92de81055f2b58310a68c0cac))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-utils-v1.70.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.69.4...@adobe/spacecat-shared-utils-v1.70.0) (2025-11-06)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.71.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@adobe/fetch": "4.2.3",
|
|
56
|
-
"@aws-sdk/client-s3": "3.
|
|
57
|
-
"@aws-sdk/client-sqs": "3.
|
|
56
|
+
"@aws-sdk/client-s3": "3.927.0",
|
|
57
|
+
"@aws-sdk/client-sqs": "3.927.0",
|
|
58
58
|
"@json2csv/plainjs": "7.0.6",
|
|
59
59
|
"aws-xray-sdk": "3.11.0",
|
|
60
60
|
"cheerio": "1.1.2",
|
package/src/url-extractors.js
CHANGED
|
@@ -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
|
-
|
|
140
|
+
const finalUrl = await getFinalRedirectUrl(url);
|
|
141
|
+
urls.push(finalUrl);
|
|
111
142
|
}
|
|
112
143
|
}
|
|
113
144
|
break;
|