@adobe/spacecat-shared-rum-api-client 1.1.2 → 1.2.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-rum-api-client-v1.2.1](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v1.2.0...@adobe/spacecat-shared-rum-api-client-v1.2.1) (2023-12-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * make RUMOptions optional ([6c2825b](https://github.com/adobe-rnd/spacecat-shared/commit/6c2825b49977ce50bc998258e9f23c73cc822b22))
7
+
8
+ # [@adobe/spacecat-shared-rum-api-client-v1.2.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v1.1.2...@adobe/spacecat-shared-rum-api-client-v1.2.0) (2023-12-15)
9
+
10
+
11
+ ### Features
12
+
13
+ * add support for 404 report backlink ([0d622de](https://github.com/adobe-rnd/spacecat-shared/commit/0d622de241b51f0df625679591dd5168b5b070a7))
14
+
1
15
  # [@adobe/spacecat-shared-rum-api-client-v1.1.2](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v1.1.1...@adobe/spacecat-shared-rum-api-client-v1.1.2) (2023-12-14)
2
16
 
3
17
 
package/README.md CHANGED
@@ -29,13 +29,23 @@ const domainKey = "your-domain-key";
29
29
  const rumApiClient = new RUMAPIClient(domainKey);
30
30
  ```
31
31
 
32
- ### Creating a Backlink
32
+ ### Creating a RUM Backlink
33
33
 
34
34
  ```js
35
35
  const url = "https://example.com";
36
- const expiry = 7; // in days
36
+ const expiryInDays = 7;
37
37
 
38
- const backlink = await rumApiClient.createBacklink(url, expiry);
38
+ const backlink = await rumApiClient.createRUMBacklink(url, expiryInDays);
39
+ console.log(`Backlink created: ${backlink}`)
40
+ ```
41
+
42
+ ### Creating a 404 Report Backlink
43
+
44
+ ```js
45
+ const url = "https://example.com";
46
+ const expiryInDays = 7;
47
+
48
+ const backlink = await rumApiClient.create404Backlink(url, expiryInDays);
39
49
  console.log(`Backlink created: ${backlink}`)
40
50
  ```
41
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -42,6 +42,6 @@
42
42
  "nock": "13.4.0",
43
43
  "sinon": "17.0.1",
44
44
  "sinon-chai": "3.7.0",
45
- "typescript": "5.3.2"
45
+ "typescript": "5.3.3"
46
46
  }
47
47
  }
package/src/index.d.ts CHANGED
@@ -13,9 +13,10 @@
13
13
  import { UniversalContext } from '@adobe/helix-universal';
14
14
 
15
15
  export interface RUMAPIOptions {
16
- interval: number;
17
- offset: number;
18
- limit: number;
16
+ interval?: number;
17
+ offset?: number;
18
+ limit?: number;
19
+ url?: string;
19
20
  }
20
21
 
21
22
  export default class RUMAPIClient {
@@ -38,14 +39,24 @@ export default class RUMAPIClient {
38
39
  constructor(domainkey: string);
39
40
 
40
41
  /**
41
- * Asynchronous method to create a backlink.
42
+ * Asynchronous method to create a RUM backlink.
42
43
  * @param {string} url - A string representing the URL for the backlink.
43
44
  * @param {number} expiry - An integer representing the expiry value for the backlink.
44
45
  * @returns A Promise resolving to a string representing url of the created backlink.
45
46
  * @remarks This method creates a backlink to the RUM dashboard, allowing users
46
47
  * to view their reports and monitor real user activities.
47
48
  */
48
- createBacklink(url: string, expiry: number): Promise<string>;
49
+ createRUMBacklink(url: string, expiry: number): Promise<string>;
50
+
51
+ /**
52
+ * Asynchronous method to create a 404 backlink.
53
+ * @param {string} url - A string representing the URL for the backlink.
54
+ * @param {number} expiry - An integer representing the expiry value for the backlink.
55
+ * @returns A Promise resolving to a string representing url of the created backlink.
56
+ * @remarks This method creates a backlink to the 404 report, allowing users
57
+ * to view their 404 pages.
58
+ */
59
+ create404Backlink(url: string, expiry: number): Promise<string>;
49
60
 
50
61
  /**
51
62
  * Asynchronous method to return the RUM dashboard API call response data.
package/src/index.js CHANGED
@@ -18,6 +18,7 @@ import { fetch } from './utils.js';
18
18
  const APIS = {
19
19
  ROTATE_DOMAINKEYS: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rotate-domainkeys',
20
20
  RUM_DASHBOARD_UI: 'https://main--franklin-dashboard--adobe.hlx.live/views/rum-dashboard',
21
+ NOT_FOUND_DASHBOARD_UI: 'https://main--franklin-dashboard--adobe.hlx.live/views/404-report',
21
22
  RUM_DASHBOARD: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-dashboard',
22
23
  DOMAIN_LIST: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/dash/domain-list',
23
24
  RUM_SOURCES: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-sources',
@@ -81,6 +82,11 @@ async function generateDomainKey(domainkey, url, expiry) {
81
82
  return data[0].key;
82
83
  }
83
84
 
85
+ async function createBacklink(dashboardUrl, domainKey, domainUrl, expiry) {
86
+ const scopedDomainKey = await generateDomainKey(domainKey, domainUrl, expiry);
87
+ return `${dashboardUrl}?interval=${expiry}&offset=0&limit=100&url=${domainUrl}&domainkey=${scopedDomainKey}`;
88
+ }
89
+
84
90
  export default class RUMAPIClient {
85
91
  static createFrom(context) {
86
92
  if (context.rumApiClient) return context.rumApiClient;
@@ -125,8 +131,11 @@ export default class RUMAPIClient {
125
131
  return data.map((row) => row.hostname);
126
132
  }
127
133
 
128
- async createBacklink(url, expiry) {
129
- const scopedDomainKey = await generateDomainKey(this.domainkey, url, expiry);
130
- return `${APIS.RUM_DASHBOARD_UI}?interval=${expiry}&offset=0&limit=100&url=${url}&domainkey=${scopedDomainKey}`;
134
+ async createRUMBacklink(url, expiry) {
135
+ return createBacklink(APIS.RUM_DASHBOARD_UI, this.domainkey, url, expiry);
136
+ }
137
+
138
+ async create404Backlink(url, expiry) {
139
+ return createBacklink(APIS.NOT_FOUND_DASHBOARD_UI, this.domainkey, url, expiry);
131
140
  }
132
141
  }