@adobe/spacecat-shared-rum-api-client 1.0.0 → 1.1.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-rum-api-client-v1.1.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v1.0.0...@adobe/spacecat-shared-rum-api-client-v1.1.0) (2023-12-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * add rum api calls to shared ([56cccd0](https://github.com/adobe-rnd/spacecat-shared/commit/56cccd0f498eaca6a4bb35a6b64d5f0dbe68a096))
7
+
1
8
  # @adobe/spacecat-shared-rum-api-client-v1.0.0 (2023-12-12)
2
9
 
3
10
 
package/README.md CHANGED
@@ -39,6 +39,33 @@ const backlink = await rumApiClient.createBacklink(url, expiry);
39
39
  console.log(`Backlink created: ${backlink}`)
40
40
  ```
41
41
 
42
+ ### Getting RUM Dashboard Data
43
+
44
+ ```js
45
+ const url = "example.com";
46
+
47
+ const rumData = await rumApiClient.getRUMDashboard({ url });
48
+ console.log(`RUM data: ${rumData}`)
49
+ ```
50
+
51
+ ### Getting 404 checkpoints
52
+
53
+ ```js
54
+ const url = "example.com";
55
+
56
+ const backlink = await rumApiClient.get404Sources({ url });
57
+ console.log(`404 Checkpoints: ${backlink}`)
58
+ ```
59
+
60
+ ### Getting Edge Delivery Services Domains
61
+
62
+ ```js
63
+ const url = "all";
64
+
65
+ const domains = await rumApiClient.getDomainList({}, url);
66
+ console.log(`Backlink created: ${backlink}`)
67
+ ```
68
+
42
69
  ## Testing
43
70
  Run the included tests with the following command:
44
71
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -33,7 +33,7 @@
33
33
  "@adobe/fetch": "4.1.1",
34
34
  "@adobe/helix-shared-wrap": "2.0.0",
35
35
  "@adobe/helix-universal": "4.4.1",
36
- "@adobe/spacecat-shared-utils": "1.3.0",
36
+ "@adobe/spacecat-shared-utils": "1.4.0",
37
37
  "aws4": "1.12.0"
38
38
  },
39
39
  "devDependencies": {
package/src/index.d.ts CHANGED
@@ -12,6 +12,12 @@
12
12
 
13
13
  import { UniversalContext } from '@adobe/helix-universal';
14
14
 
15
+ export interface RUMAPIOptions {
16
+ interval: number;
17
+ offset: number;
18
+ limit: number;
19
+ }
20
+
15
21
  export declare class RUMAPIClient {
16
22
  /**
17
23
  * Static factory method to create an instance of RUMAPIClient.
@@ -40,4 +46,30 @@ export declare class RUMAPIClient {
40
46
  * to view their reports and monitor real user activities.
41
47
  */
42
48
  createBacklink(url: string, expiry: number): Promise<string>;
49
+
50
+ /**
51
+ * Asynchronous method to return the RUM dashboard API call response data.
52
+ * @param {RUMAPIOptions} params - An object representing the parameters to be included
53
+ * for the RUM Dashboard API call.
54
+ * @returns A Promise resolving to the RUM dashboard response data.
55
+ */
56
+ getRUMDashboard(params?: RUMAPIOptions): Promise<Array<object>>;
57
+
58
+ /**
59
+ * Asynchronous method to return the 404 sources API call response data.
60
+ * @param {RUMAPIOptions} params - An object representing the parameters to be included
61
+ * for the 404 sources API call.
62
+ * @returns A Promise resolving to the 404 sources response data.
63
+ */
64
+ get404Sources(params?: RUMAPIOptions): Promise<Array<object>>;
65
+
66
+ /**
67
+ * Asynchronous method to return an array with the domain for a specific url
68
+ * or an array of all domain urls
69
+ * @param {RUMAPIOptions} params - An object representing the parameters to be included
70
+ * for the domain list call.
71
+ * @returns A Promise resolving to an array of the domain for a specific url
72
+ * or an array of all domain urls .
73
+ */
74
+ getDomainList(params?: RUMAPIOptions): Promise<Array<string>>;
43
75
  }
package/src/index.js CHANGED
@@ -17,7 +17,22 @@ import { fetch } from './utils.js';
17
17
 
18
18
  const APIS = {
19
19
  ROTATE_DOMAINKEYS: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rotate-domainkeys',
20
- RUM_DASHBOARD: 'https://main--franklin-dashboard--adobe.hlx.live/views/rum-dashboard',
20
+ RUM_DASHBOARD_UI: 'https://main--franklin-dashboard--adobe.hlx.live/views/rum-dashboard',
21
+ RUM_DASHBOARD: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-dashboard',
22
+ DOMAIN_LIST: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/dash/domain-list',
23
+ RUM_SOURCES: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-sources',
24
+ };
25
+
26
+ const DOMAIN_LIST_DEFAULT_PARAMS = {
27
+ interval: 30,
28
+ offset: 0,
29
+ limit: 100000,
30
+ };
31
+
32
+ export const RUM_DEFAULT_PARAMS = {
33
+ interval: 7,
34
+ offset: 0,
35
+ limit: 101,
21
36
  };
22
37
 
23
38
  export async function sendRequest(url, opts) {
@@ -85,8 +100,33 @@ export default class RUMAPIClient {
85
100
  this.domainkey = domainkey;
86
101
  }
87
102
 
103
+ async getRUMDashboard(params = {}) {
104
+ return sendRequest(createUrl(
105
+ APIS.RUM_DASHBOARD,
106
+ { domainkey: this.domainkey, ...RUM_DEFAULT_PARAMS, ...params },
107
+ ));
108
+ }
109
+
110
+ async get404Sources(params = {}) {
111
+ return sendRequest(createUrl(
112
+ APIS.RUM_SOURCES,
113
+ {
114
+ domainkey: this.domainkey, ...RUM_DEFAULT_PARAMS, checkpoint: 404, ...params,
115
+ },
116
+ ));
117
+ }
118
+
119
+ async getDomainList(params = {}) {
120
+ const data = await sendRequest(createUrl(
121
+ APIS.DOMAIN_LIST,
122
+ { domainkey: this.domainkey, ...DOMAIN_LIST_DEFAULT_PARAMS, ...params },
123
+ ));
124
+
125
+ return data.map((row) => row.hostname);
126
+ }
127
+
88
128
  async createBacklink(url, expiry) {
89
129
  const scopedDomainKey = await generateDomainKey(this.domainkey, url, expiry);
90
- return `${APIS.RUM_DASHBOARD}?interval=${expiry}&offset=0&limit=100&url=${url}&domainkey=${scopedDomainKey}`;
130
+ return `${APIS.RUM_DASHBOARD_UI}?interval=${expiry}&offset=0&limit=100&url=${url}&domainkey=${scopedDomainKey}`;
91
131
  }
92
132
  }