From 263262a04042b6ca69963e5933f1bca8029ba23c Mon Sep 17 00:00:00 2001 From: Tanuj Mittal Date: Wed, 27 Jan 2021 13:38:58 +0530 Subject: [PATCH] Update Juno endpoints to pass subscriptionId (#339) Corresponding [server side change](https://msdata.visualstudio.com/CosmosDB/_git/CosmosDB-portal/pullrequest/464443?_a=overview) has been deployed to Prod so now we can go ahead with DE side changes. --- src/Juno/JunoClient.test.ts | 2 +- src/Juno/JunoClient.ts | 67 ++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/Juno/JunoClient.test.ts b/src/Juno/JunoClient.test.ts index 2255df7ce..999627974 100644 --- a/src/Juno/JunoClient.test.ts +++ b/src/Juno/JunoClient.test.ts @@ -248,7 +248,7 @@ describe("Gallery", () => { const authorizationHeader = getAuthorizationHeader(); expect(response.status).toBe(HttpStatusCodes.OK); expect(window.fetch).toBeCalledWith( - `${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleDatabaseAccount.name}/gallery/${id}/favorite`, + `${configContext.JUNO_ENDPOINT}/api/notebooks/${sampleSubscriptionId}/${sampleDatabaseAccount.name}/gallery/${id}/favorite`, { method: "PATCH", headers: { diff --git a/src/Juno/JunoClient.ts b/src/Juno/JunoClient.ts index 557fe29d0..8b9d0a590 100644 --- a/src/Juno/JunoClient.ts +++ b/src/Juno/JunoClient.ts @@ -80,7 +80,7 @@ export class JunoClient { } public async getPinnedRepos(scope: string): Promise> { - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/github/pinnedrepos`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/github/pinnedrepos`, { headers: JunoClient.getHeaders(), }); @@ -103,7 +103,7 @@ export class JunoClient { } public async updatePinnedRepos(repos: IPinnedRepo[]): Promise> { - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/github/pinnedrepos`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/github/pinnedrepos`, { method: "PUT", body: JSON.stringify(repos), headers: JunoClient.getHeaders(), @@ -120,7 +120,7 @@ export class JunoClient { } public async deleteGitHubInfo(): Promise> { - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/github`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/github`, { method: "DELETE", headers: JunoClient.getHeaders(), }); @@ -135,9 +135,12 @@ export class JunoClient { const githubParams = JunoClient.getGitHubClientParams(); githubParams.append("code", code); - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/github/token?${githubParams.toString()}`, { - headers: JunoClient.getHeaders(), - }); + const response = await window.fetch( + `${this.getNotebooksSubscriptionIdAccountUrl()}/github/token?${githubParams.toString()}`, + { + headers: JunoClient.getHeaders(), + } + ); let data: IGitHubOAuthToken; const body = await response.text(); @@ -159,10 +162,13 @@ export class JunoClient { const githubParams = JunoClient.getGitHubClientParams(); githubParams.append("access_token", token); - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/github/token?${githubParams.toString()}`, { - method: "DELETE", - headers: JunoClient.getHeaders(), - }); + const response = await window.fetch( + `${this.getNotebooksSubscriptionIdAccountUrl()}/github/token?${githubParams.toString()}`, + { + method: "DELETE", + headers: JunoClient.getHeaders(), + } + ); return { status: response.status, @@ -179,7 +185,7 @@ export class JunoClient { } public async getPublicGalleryData(): Promise> { - const url = `${this.getNotebooksAccountUrl()}/gallery/public`; + const url = `${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/public`; const response = await window.fetch(url, { method: "PATCH", headers: JunoClient.getHeaders(), @@ -197,7 +203,7 @@ export class JunoClient { } public async acceptCodeOfConduct(): Promise> { - const url = `${this.getNotebooksAccountUrl()}/gallery/acceptCodeOfConduct`; + const url = `${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/acceptCodeOfConduct`; const response = await window.fetch(url, { method: "PATCH", headers: JunoClient.getHeaders(), @@ -215,7 +221,7 @@ export class JunoClient { } public async isCodeOfConductAccepted(): Promise> { - const url = `${this.getNotebooksAccountUrl()}/gallery/isCodeOfConductAccepted`; + const url = `${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/isCodeOfConductAccepted`; const response = await window.fetch(url, { method: "PATCH", headers: JunoClient.getHeaders(), @@ -294,7 +300,7 @@ export class JunoClient { } public async favoriteNotebook(id: string): Promise> { - const response = await window.fetch(`${this.getNotebooksAccountUrl()}/gallery/${id}/favorite`, { + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery/${id}/favorite`, { method: "PATCH", headers: JunoClient.getHeaders(), }); @@ -365,22 +371,19 @@ export class JunoClient { content: string, isLinkInjectionEnabled: boolean ): Promise> { - const response = await window.fetch( - `${this.getNotebooksUrl()}/${this.getSubscriptionId()}/${this.getAccount()}/gallery`, - { - method: "PUT", - headers: JunoClient.getHeaders(), - body: JSON.stringify({ - name, - description, - tags, - author, - thumbnailUrl, - content: JSON.parse(content), - addLinkToNotebookViewer: isLinkInjectionEnabled, - } as IPublishNotebookRequest), - } - ); + const response = await window.fetch(`${this.getNotebooksSubscriptionIdAccountUrl()}/gallery`, { + method: "PUT", + headers: JunoClient.getHeaders(), + body: JSON.stringify({ + name, + description, + tags, + author, + thumbnailUrl, + content: JSON.parse(content), + addLinkToNotebookViewer: isLinkInjectionEnabled, + } as IPublishNotebookRequest), + }); let data: IGalleryItem; if (response.status === HttpStatusCodes.OK) { @@ -502,6 +505,10 @@ export class JunoClient { return `${this.getNotebooksUrl()}/${this.getAccount()}`; } + private getNotebooksSubscriptionIdAccountUrl(): string { + return `${this.getNotebooksUrl()}/${this.getSubscriptionId()}/${this.getAccount()}`; + } + private getAnalyticsUrl(): string { return `${configContext.JUNO_ENDPOINT}/api/analytics`; }