From 317ca32148d266415dbfdceaf35c3630db73f5b8 Mon Sep 17 00:00:00 2001 From: alinarublea Date: Wed, 13 Dec 2023 14:37:16 +0100 Subject: [PATCH 1/4] feat: add rum api calls to shared --- .../src/index.js | 16 +++++++++++++ .../test/rum-api-client.test.js | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/packages/spacecat-shared-rum-api-client/src/index.js b/packages/spacecat-shared-rum-api-client/src/index.js index 195fd2a7..fda9255c 100644 --- a/packages/spacecat-shared-rum-api-client/src/index.js +++ b/packages/spacecat-shared-rum-api-client/src/index.js @@ -18,6 +18,8 @@ import { fetch } from './utils.js'; const APIS = { ROTATE_DOMAINKEYS: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rotate-domainkeys', RUM_DASHBOARD: 'https://main--franklin-dashboard--adobe.hlx.live/views/rum-dashboard', + DOMAIN_LIST: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-dashboard', + NOT_FOUND_CHECKPOINTS: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-checkpoint-urls', }; export async function sendRequest(url, opts) { @@ -85,6 +87,20 @@ export default class RUMAPIClient { this.domainkey = domainkey; } + async getRUMDashboard(params) { + return sendRequest(createUrl( + APIS.DOMAIN_LIST, + { domainkey: this.domainkey, ...params }, + )); + } + + async get404Checkpoints(params) { + return sendRequest(createUrl( + APIS.NOT_FOUND_CHECKPOINTS, + { domainkey: this.domainkey, ...params }, + )); + } + async createBacklink(url, expiry) { const scopedDomainKey = await generateDomainKey(this.domainkey, url, expiry); return `${APIS.RUM_DASHBOARD}?interval=${expiry}&offset=0&limit=100&url=${url}&domainkey=${scopedDomainKey}`; diff --git a/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js b/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js index fad0eb76..9418a51c 100644 --- a/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js +++ b/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js @@ -59,4 +59,28 @@ describe('rum api client', () => { await expect(sendRequest('https://space.cat/dummy-page')) .to.be.rejectedWith('Unexpected response from rum api. $.results.data is not array'); }); + + it('returns data when getRUMDashboard api is successful', async () => { + nock('https://helix-pages.anywhere.run/helix-services') + .get('/run-query@v3/rum-dashboard') + .query({ + domainkey: 'hebele', + }) + .reply(200, JSON.stringify({ results: { data: [] } })); + const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_API_KEY: 'hebele' } }); + await expect(rumApiClient.getRUMDashboard()) + .to.be.fulfilled; + }); + + it('returns data when get404Checkpoints api is successful', async () => { + nock('https://helix-pages.anywhere.run/helix-services') + .get('/run-query@v3/rum-checkpoint-urls') + .query({ + domainkey: 'hebele', + }) + .reply(200, JSON.stringify({ results: { data: [] } })); + const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_API_KEY: 'hebele' } }); + await expect(rumApiClient.get404Checkpoints()) + .to.be.fulfilled; + }); }); From 08586db457db94f1cb6e95cebeab0cfdd08a77bd Mon Sep 17 00:00:00 2001 From: alinarublea Date: Wed, 28 Aug 2024 15:09:19 +0200 Subject: [PATCH 2/4] fix: docs and migration script --- package-lock.json | 1 + .../src/clients/content-client.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 814490ac..b42e47f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17986,6 +17986,7 @@ } }, "packages/spacecat-shared-content-client": { + "name": "@adobe/spacecat-shared-content-client", "version": "1.0.0", "license": "Apache-2.0", "dependencies": { diff --git a/packages/spacecat-shared-content-client/src/clients/content-client.js b/packages/spacecat-shared-content-client/src/clients/content-client.js index 23d01252..a9e8d1b4 100644 --- a/packages/spacecat-shared-content-client/src/clients/content-client.js +++ b/packages/spacecat-shared-content-client/src/clients/content-client.js @@ -174,7 +174,8 @@ export default class ContentClient { this.log.info(`Updating page metadata for ${this.site.getId()} and path ${path}`); const docPath = this.#resolveDocPath(path); - const originalMetadata = await this.getPageMetadata(docPath); + this.log.info(`Getting page metadata for ${this.site.getId()} and path ${path}`); + const originalMetadata = await this.rawClient.getPageMetadata(docPath); let mergedMetadata; if (overwrite) { From 6bcbbbeaec9324ebd5f970870762fcd4b8f80a9c Mon Sep 17 00:00:00 2001 From: alinarublea Date: Thu, 29 Aug 2024 15:42:04 +0200 Subject: [PATCH 3/4] fix: docs and migration script --- .../src/clients/content-client.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/spacecat-shared-content-client/src/clients/content-client.js b/packages/spacecat-shared-content-client/src/clients/content-client.js index a9e8d1b4..1f6fae85 100644 --- a/packages/spacecat-shared-content-client/src/clients/content-client.js +++ b/packages/spacecat-shared-content-client/src/clients/content-client.js @@ -174,8 +174,7 @@ export default class ContentClient { this.log.info(`Updating page metadata for ${this.site.getId()} and path ${path}`); const docPath = this.#resolveDocPath(path); - this.log.info(`Getting page metadata for ${this.site.getId()} and path ${path}`); - const originalMetadata = await this.rawClient.getPageMetadata(docPath); + const originalMetadata = await this.getPageMetadata(path); let mergedMetadata; if (overwrite) { From 2308c79fe76fccf4f51f18c95bc072443d0a2202 Mon Sep 17 00:00:00 2001 From: alinarublea Date: Thu, 29 Aug 2024 15:45:00 +0200 Subject: [PATCH 4/4] fix: docs and migration script --- package-lock.json | 9 ++++----- packages/spacecat-shared-content-client/package.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b42e47f0..2fa71fbf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -251,10 +251,9 @@ } }, "node_modules/@adobe/spacecat-helix-content-sdk": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@adobe/spacecat-helix-content-sdk/-/spacecat-helix-content-sdk-1.1.2.tgz", - "integrity": "sha512-CR/3V5fsgKok4OyNPD8R1yw4j0WQY7yT4R6G/F7ayUYNSFXWV1oDb2PD03JB9L21uv6gpcJgI/EGUYCmad3+9Q==", - "license": "Apache-2.0", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@adobe/spacecat-helix-content-sdk/-/spacecat-helix-content-sdk-1.1.3.tgz", + "integrity": "sha512-2Xd5Iir7NNoUir6OURoze0jBjLI3CH2pV1RM99tvKG+BRHUMogjjHuLajdUsrsB6CXegOW/cev8uttaHtHFu4A==", "dependencies": { "@adobe/fetch": "4.1.8", "@adobe/helix-docx2md": "1.6.5", @@ -17991,7 +17990,7 @@ "license": "Apache-2.0", "dependencies": { "@adobe/helix-universal": "5.0.5", - "@adobe/spacecat-helix-content-sdk": "1.1.2", + "@adobe/spacecat-helix-content-sdk": "1.1.3", "@adobe/spacecat-shared-utils": "1.19.6" }, "devDependencies": { diff --git a/packages/spacecat-shared-content-client/package.json b/packages/spacecat-shared-content-client/package.json index c6bc9d9d..90d2242c 100644 --- a/packages/spacecat-shared-content-client/package.json +++ b/packages/spacecat-shared-content-client/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "@adobe/helix-universal": "5.0.5", - "@adobe/spacecat-helix-content-sdk": "1.1.2", + "@adobe/spacecat-helix-content-sdk": "1.1.3", "@adobe/spacecat-shared-utils": "1.19.6" }, "devDependencies": {