mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-06-30 02:28:44 +01:00
cff1434901
Removes the GitHub notebook-repo integration that only existed to pin/browse notebook repositories. Deletes src/GitHub/, the GitHub controls/panes, GitHubUtils, JunoUtils, and the connectToGitHub webpack entry. Decouples NotebookManager, useNotebook, the resource tree, and Explorer from GitHub wiring. Trims JunoClient's GitHub-only methods while keeping the Schema and gallery methods. Removes GitHub config fields from ConfigContext and strips the dead github:// branches from NotebookUtil. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
137 lines
3.6 KiB
TypeScript
137 lines
3.6 KiB
TypeScript
import { allowedJunoOrigins, validateEndpoint } from "Utils/EndpointUtils";
|
|
import { HttpHeaders, HttpStatusCodes } from "../Common/Constants";
|
|
import { configContext } from "../ConfigContext";
|
|
import * as DataModels from "../Contracts/DataModels";
|
|
import { userContext } from "../UserContext";
|
|
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
|
|
|
export interface IJunoResponse<T> {
|
|
status: number;
|
|
data: T;
|
|
}
|
|
|
|
export interface IGalleryItem {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
gitSha: string;
|
|
tags: string[];
|
|
author: string;
|
|
thumbnailUrl: string;
|
|
created: string;
|
|
isSample: boolean;
|
|
downloads: number;
|
|
favorites: number;
|
|
views: number;
|
|
newCellId: string;
|
|
policyViolations: string[];
|
|
pendingScanJobIds: string[];
|
|
}
|
|
|
|
export class JunoClient {
|
|
public async increaseNotebookViews(id: string): Promise<IJunoResponse<IGalleryItem>> {
|
|
const response = await window.fetch(`${this.getNotebooksUrl()}/gallery/${id}/views`, {
|
|
method: "PATCH",
|
|
});
|
|
|
|
let data: IGalleryItem;
|
|
if (response.status === HttpStatusCodes.OK) {
|
|
data = await response.json();
|
|
}
|
|
|
|
return {
|
|
status: response.status,
|
|
data,
|
|
};
|
|
}
|
|
|
|
public async requestSchema(
|
|
schemaRequest: DataModels.ISchemaRequest,
|
|
): Promise<IJunoResponse<DataModels.ISchemaRequest>> {
|
|
const response = await window.fetch(`${this.getAnalyticsUrl()}/schema/request`, {
|
|
method: "POST",
|
|
body: JSON.stringify(schemaRequest),
|
|
headers: JunoClient.getHeaders(),
|
|
});
|
|
|
|
let data: DataModels.ISchemaRequest;
|
|
if (response.status === HttpStatusCodes.OK) {
|
|
data = await response.json();
|
|
}
|
|
|
|
return {
|
|
status: response.status,
|
|
data,
|
|
};
|
|
}
|
|
|
|
public async getSchema(
|
|
subscriptionId: string,
|
|
resourceGroup: string,
|
|
accountName: string,
|
|
databaseName: string,
|
|
containerName: string,
|
|
): Promise<IJunoResponse<DataModels.ISchema>> {
|
|
const response = await window.fetch(
|
|
`${this.getAnalyticsUrl()}/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/databaseAccounts/${accountName}/schema/${databaseName}/${containerName}`,
|
|
{
|
|
method: "GET",
|
|
headers: JunoClient.getHeaders(),
|
|
},
|
|
);
|
|
|
|
let data: DataModels.ISchema;
|
|
|
|
if (response.status === HttpStatusCodes.OK) {
|
|
data = await response.json();
|
|
}
|
|
|
|
return {
|
|
status: response.status,
|
|
data,
|
|
};
|
|
}
|
|
|
|
private async getNotebooks(input: RequestInfo, init?: RequestInit): Promise<IJunoResponse<IGalleryItem[]>> {
|
|
const response = await window.fetch(input, init);
|
|
|
|
let data: IGalleryItem[];
|
|
if (response.status === HttpStatusCodes.OK) {
|
|
data = await response.json();
|
|
}
|
|
|
|
return {
|
|
status: response.status,
|
|
data,
|
|
};
|
|
}
|
|
|
|
// public for tests
|
|
public static getJunoEndpoint(): string {
|
|
const junoEndpoint = userContext.features.junoEndpoint ?? configContext.JUNO_ENDPOINT;
|
|
if (!validateEndpoint(junoEndpoint, allowedJunoOrigins)) {
|
|
const error = `${junoEndpoint} not allowed as juno endpoint`;
|
|
console.error(error);
|
|
throw new Error(error);
|
|
}
|
|
|
|
return junoEndpoint;
|
|
}
|
|
|
|
private getNotebooksUrl(): string {
|
|
return `${JunoClient.getJunoEndpoint()}/api/notebooks`;
|
|
}
|
|
|
|
private getAnalyticsUrl(): string {
|
|
return `${JunoClient.getJunoEndpoint()}/api/analytics`;
|
|
}
|
|
|
|
private static getHeaders(): HeadersInit {
|
|
const authorizationHeader = getAuthorizationHeader();
|
|
return {
|
|
[authorizationHeader.header]: authorizationHeader.token,
|
|
[HttpHeaders.contentType]: "application/json",
|
|
};
|
|
}
|
|
}
|