Skip to content

Commit

Permalink
chore: namananand/ins-3307-add-new-api-end-points-which-where-added-o…
Browse files Browse the repository at this point in the history
…n-the-console (#57)

Because

- add-new-api-end-points-which-where-added-on-the-console

This commit

- add-new-api-end-points-which-where-added-on-the-console
  • Loading branch information
iamnamananand996 authored Jan 19, 2024
1 parent 220cd28 commit 9ac18eb
Show file tree
Hide file tree
Showing 23 changed files with 2,648 additions and 417 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"access": "public"
},
"dependencies": {
"@instill-ai/toolkit": "0.68.0-rc.23",
"@instill-ai/toolkit": "0.78.1",
"@types/json-schema": "^7.0.11",
"axios": "^1.3.4",
"json-schema": "^0.4.0",
Expand Down
1,526 changes: 1,400 additions & 126 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

125 changes: 58 additions & 67 deletions src/connector/ConnectorClient.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import axios, { AxiosInstance } from "axios";
import { Nullable } from "../types";
import {
CreateUserConnectorResourcePayload,
RenameUserConnectorResourcePayload,
UpdateUserConnectorResourcePayload,
} from "./types";
import { getQueryString } from "../helper";
import {
getConnectorDefinitionQuery,
getUserConnectorResourceQuery,
getUserConnectorQuery,
listConnectorDefinitionsQuery,
listConnectorResourcesQuery,
listUserConnectorResourcesQuery,
watchUserConnectorResource,
listConnectorsQuery,
listUserConnectorsQuery,
watchUserConnector,
} from "./queries";
import {
createUserConnectorResourceMutation,
deleteUserConnectorResourceMutation,
renameUserConnectorResource,
updateUserConnectorResourceMutation,
createUserConnectorMutation,
deleteUserConnectorMutation,
renameUserConnector,
updateUserConnectorMutation,
} from "./mutation";
import {
connectUserConnectorResourceAction,
disconnectUserConnectorResourceAction,
testUserConnectorResourceConnectionAction,
testUserConnectorConnectionAction,
connectUserConnectorAction,
disconnectUserConnectorAction,
} from "./action";
import {
CreateUserConnectorPayload,
RenameUserConnectorPayload,
UpdateUserConnectorPayload,
} from "./types";

class ConnectorClient {
private axiosInstance: AxiosInstance;
Expand All @@ -44,7 +43,7 @@ class ConnectorClient {
* Connector Queries
* -----------------------------------------------------------------------*/

async listConnectorResourcesQuery({
async listConnectorsQuery({
pageSize,
nextPageToken,
filter,
Expand All @@ -53,15 +52,15 @@ class ConnectorClient {
nextPageToken: Nullable<string>;
filter: Nullable<string>;
}) {
return listConnectorResourcesQuery({
return listConnectorsQuery({
axiosInstance: this.axiosInstance,
pageSize,
nextPageToken,
filter,
});
}

async listUserConnectorResourcesQuery({
async listUserConnectorsQuery({
userName,
pageSize,
nextPageToken,
Expand All @@ -72,7 +71,7 @@ class ConnectorClient {
nextPageToken: Nullable<string>;
filter: Nullable<string>;
}) {
return listUserConnectorResourcesQuery({
return listUserConnectorsQuery({
axiosInstance: this.axiosInstance,
userName,
pageSize,
Expand Down Expand Up @@ -109,74 +108,66 @@ class ConnectorClient {
});
}

async getUserConnectorResourceQuery({
connectorResourceName,
}: {
connectorResourceName: string;
}) {
return getUserConnectorResourceQuery({
async getUserConnectorQuery({ connectorName }: { connectorName: string }) {
return getUserConnectorQuery({
axiosInstance: this.axiosInstance,
connectorResourceName,
connectorName,
});
}

async watchUserConnectorResource({
connectorResourceName,
}: {
connectorResourceName: string;
}) {
return watchUserConnectorResource({
async watchUserConnector({ connectorName }: { connectorName: string }) {
return watchUserConnector({
axiosInstance: this.axiosInstance,
connectorResourceName,
connectorName,
});
}

/* -------------------------------------------------------------------------
* Connector Mutation
* -----------------------------------------------------------------------*/

async createUserConnectorResourceMutation({
userName,
async createUserConnectorMutation({
entityName,
payload,
}: {
userName: string;
payload: CreateUserConnectorResourcePayload;
entityName: string;
payload: CreateUserConnectorPayload;
}) {
return createUserConnectorResourceMutation({
return createUserConnectorMutation({
axiosInstance: this.axiosInstance,
userName,
entityName,
payload,
});
}

async deleteUserConnectorResourceMutation({
connectorResourceName,
async deleteUserConnectorMutation({
connectorName,
}: {
connectorResourceName: string;
connectorName: string;
}) {
return deleteUserConnectorResourceMutation({
return deleteUserConnectorMutation({
axiosInstance: this.axiosInstance,
connectorResourceName,
connectorName,
});
}

async updateUserConnectorResourceMutation({
async updateUserConnectorMutation({
payload,
}: {
payload: UpdateUserConnectorResourcePayload;
payload: UpdateUserConnectorPayload;
}) {
return updateUserConnectorResourceMutation({
return updateUserConnectorMutation({
axiosInstance: this.axiosInstance,
payload,
});
}

async renameUserConnectorResource({
async renameUserConnector({
payload,
}: {
payload: RenameUserConnectorResourcePayload;
payload: RenameUserConnectorPayload;
}) {
return renameUserConnectorResource({
return renameUserConnector({
axiosInstance: this.axiosInstance,
payload,
});
Expand All @@ -186,36 +177,36 @@ class ConnectorClient {
* Connector Action
* -----------------------------------------------------------------------*/

async testUserConnectorResourceConnectionAction({
connectorResourceName,
async testUserConnectorConnectionAction({
connectorName,
}: {
connectorResourceName: string;
connectorName: string;
}) {
return testUserConnectorResourceConnectionAction({
return testUserConnectorConnectionAction({
axiosInstance: this.axiosInstance,
connectorResourceName,
connectorName,
});
}

async connectUserConnectorResourceAction({
connectorResourceName,
async connectUserConnectorAction({
connectorName,
}: {
connectorResourceName: string;
connectorName: string;
}) {
return connectUserConnectorResourceAction({
return connectUserConnectorAction({
axiosInstance: this.axiosInstance,
connectorResourceName,
connectorName,
});
}

async disconnectUserConnectorResourceAction({
connectorResourceName,
async disconnectUserConnectorAction({
connectorName,
}: {
connectorResourceName: string;
connectorName: string;
}) {
return disconnectUserConnectorResourceAction({
return disconnectUserConnectorAction({
axiosInstance: this.axiosInstance,
connectorResourceName,
connectorName,
});
}
}
Expand Down
58 changes: 32 additions & 26 deletions src/connector/action.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
import { AxiosInstance } from "axios";
import {
ConnectUserConnectorResourceResponse,
DisconnectUserConnectorResourceResponse,
TestUserConnectorResourceConnectionResponse,
} from "./types";
import { ConnectorState, ConnectorWithDefinition } from "./types";

export async function testUserConnectorResourceConnectionAction({
export type TestUserConnectorConnectionResponse = {
state: ConnectorState;
};

export async function testUserConnectorConnectionAction({
axiosInstance,
connectorResourceName,
connectorName,
}: {
axiosInstance: AxiosInstance;
connectorResourceName: string;
connectorName: string;
}) {
try {
const { data } =
await axiosInstance.post<TestUserConnectorResourceConnectionResponse>(
`/${connectorResourceName}/testConnection`
await axiosInstance.post<TestUserConnectorConnectionResponse>(
`/${connectorName}/testConnection`
);
return Promise.resolve(data.state);
} catch (err) {
return Promise.reject(err);
}
}

export async function connectUserConnectorResourceAction({
export type ConnectUserConnectorResponse = {
connector: ConnectorWithDefinition;
};

export async function connectUserConnectorAction({
axiosInstance,
connectorResourceName,
connectorName,
}: {
axiosInstance: AxiosInstance;
connectorResourceName: string;
connectorName: string;
}) {
try {
const { data } =
await axiosInstance.post<ConnectUserConnectorResourceResponse>(
`/${connectorResourceName}/connect`
);
return Promise.resolve(data.connector_resource);
const { data } = await axiosInstance.post<ConnectUserConnectorResponse>(
`/${connectorName}/connect`
);
return Promise.resolve(data.connector);
} catch (err) {
return Promise.reject(err);
}
}

export async function disconnectUserConnectorResourceAction({
export type DisconnectUserConnectorResponse = {
connector: ConnectorWithDefinition;
};

export async function disconnectUserConnectorAction({
axiosInstance,
connectorResourceName,
connectorName,
}: {
axiosInstance: AxiosInstance;
connectorResourceName: string;
connectorName: string;
}) {
try {
const { data } =
await axiosInstance.post<DisconnectUserConnectorResourceResponse>(
`/${connectorResourceName}/disconnect`
);
return Promise.resolve(data.connector_resource);
const { data } = await axiosInstance.post<DisconnectUserConnectorResponse>(
`/${connectorName}/disconnect`
);
return Promise.resolve(data.connector);
} catch (err) {
return Promise.reject(err);
}
Expand Down
Loading

0 comments on commit 9ac18eb

Please sign in to comment.