@adobe/spacecat-shared-utils 1.11.6 → 1.12.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,10 @@
1
+ # [@adobe/spacecat-shared-utils-v1.12.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.11.6...@adobe/spacecat-shared-utils-v1.12.0) (2024-02-27)
2
+
3
+
4
+ ### Features
5
+
6
+ * add composeAuditURL to helpers ([b7d4244](https://github.com/adobe/spacecat-shared/commit/b7d42447380915204a702e9fb1dfc4ecd4e5795c))
7
+
1
8
  # [@adobe/spacecat-shared-utils-v1.11.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.11.5...@adobe/spacecat-shared-utils-v1.11.6) (2024-02-26)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.11.6",
3
+ "version": "1.12.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -84,3 +84,10 @@ declare function stripWWW(url: string): string;
84
84
  * @returns The composed base URL.
85
85
  */
86
86
  declare function composeBaseURL(domain: string): string;
87
+
88
+ /**
89
+ * Composes an audit URL by applying a series of transformations to the given url.
90
+ * @param url - The url to compose the audit URL from.
91
+ * @returns The composed audit URL.
92
+ */
93
+ declare function composeAuditURL(url: string): string;
package/src/index.js CHANGED
@@ -34,6 +34,7 @@ export { sqsEventAdapter } from './sqs.js';
34
34
 
35
35
  export {
36
36
  composeBaseURL,
37
+ composeAuditURL,
37
38
  prependSchema,
38
39
  stripPort,
39
40
  stripTrailingDot,
@@ -10,6 +10,12 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import { context as h2, h1 } from '@adobe/fetch';
14
+
15
+ /* c8 ignore next 3 */
16
+ export const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1
17
+ ? h1()
18
+ : h2();
13
19
  /**
14
20
  * Prepends 'https://' schema to the URL if it's not already present.
15
21
  * @param {string} url - The URL to modify.
@@ -72,8 +78,16 @@ function composeBaseURL(domain) {
72
78
  return baseURL;
73
79
  }
74
80
 
81
+ async function composeAuditURL(url) {
82
+ const urlWithScheme = prependSchema(url);
83
+ const resp = await fetch(urlWithScheme);
84
+ const finalUrl = resp.url.split('://')[1];
85
+ return stripTrailingSlash(finalUrl);
86
+ }
87
+
75
88
  export {
76
89
  composeBaseURL,
90
+ composeAuditURL,
77
91
  prependSchema,
78
92
  stripPort,
79
93
  stripTrailingDot,