2024-01-23 11:47:02 +00:00
|
|
|
import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
2024-01-17 08:52:15 +00:00
|
|
|
|
2024-01-29 12:48:43 +00:00
|
|
|
import { getUser, getOrganizations, getDeployments, getProjectMembers, searchProjects, getEnvironmentVariables, getProject, getDomains, getProjectsInOrganization } from './queries';
|
2024-02-01 12:40:15 +00:00
|
|
|
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse, AddDomainInput, AddDomainResponse, GetDomainsResponse, UpdateDomainInput, UpdateDomainResponse, AuthenticateGitHubResponse, UnauthenticateGitHubResponse, UpdateEnvironmentVariableResponse, UpdateEnvironmentVariableInput, RemoveEnvironmentVariableResponse, UpdateProjectMemberInput, RemoveProjectMemberResponse, UpdateProjectMemberResponse, DeleteDomainResponse, AddProjectMemberInput, AddProjectMemberResponse, AddProjectInput, AddProjectResponse } from './types';
|
|
|
|
import { removeProjectMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, addDomain, rollbackDeployment, updateDomainMutation, authenticateGitHub, unauthenticateGitHub, updateEnvironmentVariable, removeEnvironmentVariable, updateProjectMember, deleteDomain, addProjectMember, addProject } from './mutations';
|
2024-01-17 08:52:15 +00:00
|
|
|
|
|
|
|
export interface GraphQLConfig {
|
|
|
|
gqlEndpoint: string;
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
// TODO: check options
|
|
|
|
const defaultOptions: DefaultOptions = {
|
|
|
|
watchQuery: {
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'ignore'
|
|
|
|
},
|
|
|
|
query: {
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-17 08:52:15 +00:00
|
|
|
export class GQLClient {
|
|
|
|
private client: ApolloClient<NormalizedCacheObject>;
|
|
|
|
|
|
|
|
constructor (config: GraphQLConfig) {
|
|
|
|
this.client = new ApolloClient({
|
|
|
|
uri: config.gqlEndpoint,
|
2024-01-23 11:47:02 +00:00
|
|
|
cache: new InMemoryCache(),
|
|
|
|
defaultOptions
|
2024-01-17 08:52:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
async getUser () : Promise<GetUserResponse> {
|
2024-01-17 08:52:15 +00:00
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getUser
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 04:34:02 +00:00
|
|
|
|
2024-01-25 11:08:40 +00:00
|
|
|
async getProject (projectId: string) : Promise<GetProjectResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getProject,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-29 11:01:03 +00:00
|
|
|
async getProjectsInOrganization (organizationId: string) : Promise<GetProjectsInOrganizationResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getProjectsInOrganization,
|
|
|
|
variables: {
|
|
|
|
organizationId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
async getOrganizations () : Promise<GetOrganizationsResponse> {
|
2024-01-18 04:34:02 +00:00
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getOrganizations
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 12:20:50 +00:00
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
async getDeployments (projectId: string) : Promise<GetDeploymentsResponse> {
|
2024-01-18 12:20:50 +00:00
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getDeployments,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-23 11:47:02 +00:00
|
|
|
|
2024-01-25 05:14:51 +00:00
|
|
|
async getEnvironmentVariables (projectId: string) : Promise<GetEnvironmentVariablesResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getEnvironmentVariables,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-31 11:39:29 +00:00
|
|
|
async getProjectMembers (projectId: string) : Promise<GetProjectMembersResponse> {
|
|
|
|
const result = await this.client.query({
|
|
|
|
query: getProjectMembers,
|
2024-01-23 11:47:02 +00:00
|
|
|
variables: {
|
2024-01-31 11:39:29 +00:00
|
|
|
projectId
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-31 11:39:29 +00:00
|
|
|
return result.data;
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
|
|
|
|
2024-02-01 10:04:17 +00:00
|
|
|
async addProjectMember (projectId: string, data: AddProjectMemberInput) : Promise<AddProjectMemberResponse> {
|
|
|
|
const result = await this.client.mutate({
|
|
|
|
mutation: addProjectMember,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
data
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result.data;
|
|
|
|
}
|
|
|
|
|
2024-01-31 11:39:29 +00:00
|
|
|
async updateProjectMember (projectMemberId: string, data: UpdateProjectMemberInput): Promise<UpdateProjectMemberResponse> {
|
|
|
|
const result = await this.client.mutate({
|
|
|
|
mutation: updateProjectMember,
|
2024-01-23 11:47:02 +00:00
|
|
|
variables: {
|
2024-01-31 11:39:29 +00:00
|
|
|
projectMemberId,
|
|
|
|
data
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-31 11:39:29 +00:00
|
|
|
return result.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeProjectMember (projectMemberId: string): Promise<RemoveProjectMemberResponse> {
|
|
|
|
const result = await this.client.mutate({
|
|
|
|
mutation: removeProjectMember,
|
|
|
|
variables: {
|
|
|
|
projectMemberId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result.data;
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
2024-01-24 14:47:43 +00:00
|
|
|
|
|
|
|
async searchProjects (searchText: string) : Promise<SearchProjectsResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: searchProjects,
|
|
|
|
variables: {
|
|
|
|
searchText
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 05:14:51 +00:00
|
|
|
|
2024-02-05 10:51:55 +00:00
|
|
|
async addEnvironmentVariables (projectId: string, data: AddEnvironmentVariableInput[]): Promise<AddEnvironmentVariablesResponse> {
|
|
|
|
const result = await this.client.mutate({
|
2024-01-25 05:14:51 +00:00
|
|
|
mutation: addEnvironmentVariables,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
2024-02-05 10:51:55 +00:00
|
|
|
data
|
2024-01-25 05:14:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-05 10:51:55 +00:00
|
|
|
return result.data;
|
2024-01-25 05:14:51 +00:00
|
|
|
}
|
2024-01-25 05:47:44 +00:00
|
|
|
|
2024-02-05 10:51:55 +00:00
|
|
|
async updateEnvironmentVariable (environmentVariableId: string, data: UpdateEnvironmentVariableInput): Promise<UpdateEnvironmentVariableResponse> {
|
|
|
|
const result = await this.client.mutate({
|
2024-01-31 05:06:22 +00:00
|
|
|
mutation: updateEnvironmentVariable,
|
|
|
|
variables: {
|
|
|
|
environmentVariableId,
|
2024-02-05 10:51:55 +00:00
|
|
|
data
|
2024-01-31 05:06:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-05 10:51:55 +00:00
|
|
|
return result.data;
|
2024-01-31 05:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async removeEnvironmentVariable (environmentVariableId: string): Promise<RemoveEnvironmentVariableResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: removeEnvironmentVariable,
|
|
|
|
variables: {
|
|
|
|
environmentVariableId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-25 05:47:44 +00:00
|
|
|
async updateDeploymentToProd (deploymentId: string): Promise<UpdateDeploymentToProdResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: updateDeploymentToProd,
|
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 11:08:40 +00:00
|
|
|
|
2024-02-01 12:40:15 +00:00
|
|
|
async addProject (projectDetails: AddProjectInput): Promise<AddProjectResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: addProject,
|
|
|
|
variables: {
|
|
|
|
projectDetails
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-30 08:31:09 +00:00
|
|
|
async updateProject (projectId: string, projectDetails: UpdateProjectInput): Promise<UpdateProjectResponse> {
|
2024-01-25 11:08:40 +00:00
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: updateProjectMutation,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
2024-01-30 08:31:09 +00:00
|
|
|
projectDetails
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateDomain (domainId: string, domainDetails: UpdateDomainInput): Promise<UpdateDomainResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: updateDomainMutation,
|
|
|
|
variables: {
|
|
|
|
domainId,
|
|
|
|
domainDetails
|
2024-01-25 11:08:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 12:04:13 +00:00
|
|
|
|
|
|
|
async redeployToProd (deploymentId: string): Promise<RedeployToProdResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: redeployToProd,
|
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 11:01:03 +00:00
|
|
|
|
|
|
|
async deleteProject (projectId: string): Promise<DeleteProjectResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: deleteProject,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 12:09:51 +00:00
|
|
|
|
2024-02-01 03:34:24 +00:00
|
|
|
async deleteDomain (domainId: string): Promise<DeleteDomainResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: deleteDomain,
|
|
|
|
variables: {
|
|
|
|
domainId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-29 12:09:51 +00:00
|
|
|
async rollbackDeployment (projectId: string, deploymentId: string): Promise<RollbackDeploymentResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: rollbackDeployment,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 12:48:43 +00:00
|
|
|
|
|
|
|
async addDomain (projectId: string, domainDetails: AddDomainInput): Promise<AddDomainResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: addDomain,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
domainDetails
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getDomains (projectId: string): Promise<GetDomainsResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getDomains,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-30 14:20:53 +00:00
|
|
|
|
2024-01-31 13:21:53 +00:00
|
|
|
async authenticateGitHub (code: string): Promise<AuthenticateGitHubResponse> {
|
2024-01-30 14:20:53 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-01-31 13:21:53 +00:00
|
|
|
mutation: authenticateGitHub,
|
2024-01-30 14:20:53 +00:00
|
|
|
variables: {
|
|
|
|
code
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-31 13:21:53 +00:00
|
|
|
|
|
|
|
async unauthenticateGithub (): Promise<UnauthenticateGitHubResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: unauthenticateGitHub
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-17 08:52:15 +00:00
|
|
|
}
|