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-01-31 05:06:22 +00:00
|
|
|
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, RemoveMemberResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse, AddDomainInput, AddDomainResponse, GetDomainsResponse, UpdateDomainInput, UpdateDomainResponse, AuthenticateGithubResponse, UpdateEnvironmentVariableResponse, UpdateEnvironmentVariableInput, RemoveEnvironmentVariableResponse } from './types';
|
|
|
|
import { removeMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, addDomain, rollbackDeployment, updateDomainMutation, authenticateGithub, updateEnvironmentVariable, removeEnvironmentVariable } 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-23 11:47:02 +00:00
|
|
|
async removeMember (memberId: string): Promise<RemoveMemberResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: removeMember,
|
|
|
|
variables: {
|
|
|
|
memberId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getProjectMembers (projectId: string) : Promise<GetProjectMembersResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getProjectMembers,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
async addEnvironmentVariables (projectId: string, environmentVariables: AddEnvironmentVariableInput[]): Promise<AddEnvironmentVariablesResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: addEnvironmentVariables,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
environmentVariables
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 05:47:44 +00:00
|
|
|
|
2024-01-31 05:06:22 +00:00
|
|
|
async updateEnvironmentVariable (environmentVariableId: string, environmentVariable: UpdateEnvironmentVariableInput): Promise<UpdateEnvironmentVariableResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: updateEnvironmentVariable,
|
|
|
|
variables: {
|
|
|
|
environmentVariableId,
|
|
|
|
environmentVariable
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
async authenticateGithub (code: string): Promise<AuthenticateGithubResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: authenticateGithub,
|
|
|
|
variables: {
|
|
|
|
code
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-17 08:52:15 +00:00
|
|
|
}
|