diff --git a/README.md b/README.md index 20ded1f..b0c6046 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ modelDefinitionName, | function | params | | :--------------------- | :---------------------: | -| getUserQuery | | +| getUserQuery | | | checkUserIdExist | id | | getApiTokenQuery | tokenName | | listApiTokensQuery | pageSize, nextPageToken | diff --git a/examples/next-app/src/pages/index.tsx b/examples/next-app/src/pages/index.tsx index 8484f41..10229ac 100644 --- a/examples/next-app/src/pages/index.tsx +++ b/examples/next-app/src/pages/index.tsx @@ -1,73 +1,3 @@ -// import { useEffect, useState } from "react"; -// import InstillClient, { -// Nullable, -// Pipeline, -// User, -// } from "@instill-ai/typescript-sdk"; - -// export default function TypescriptSdkDemo() { -// const [pipelines, setPipelines] = useState([]); -// const [user, setUser] = useState([]); -// const [token, setToken] = useState>(null); - -// const client = new InstillClient("http://localhost:8080", "v1alpha", token); - -// const login = async () => { -// const userToken = await client.Auth.authLoginAction({ -// payload: { -// username: "admin", -// password: "password", -// }, -// }); -// setToken(userToken); -// }; - -// useEffect(() => { -// login(); -// }, []); - -// useEffect(() => { -// if (token) { -// client.Auth.getUserQuery() -// .then((data: any) => { -// console.log("data", data); -// setUser(data); -// }) -// .catch((error: any) => { -// console.log("error", error); -// }); - -// client.Pipeline.listPipelinesQuery({ -// pageSize: null, -// nextPageToken: null, -// }) -// .then((data: any) => { -// console.log("data", data); -// setPipelines(data); -// }) -// .catch((error: any) => { -// console.log("error", error); -// }); -// } -// }, [token]); - -// return ( -// <> -//

User Data

-//
-//         {JSON.stringify(user, null, 4)}
-//       
- -//

Pipelines List

-//
-//         {JSON.stringify(pipelines, null, 4)}
-//       
-// -// ); -// } - -// Console Token Implementation - import { useEffect, useState } from "react"; import InstillClient, { Nullable, @@ -78,34 +8,37 @@ import InstillClient, { export default function TypescriptSdkDemo() { const [pipelines, setPipelines] = useState([]); const [user, setUser] = useState([]); + const [token, setToken] = useState>(null); const client = new InstillClient( - "https://api.instill.tech", + "http://localhost:8080", "v1alpha", - "instill_sk_OwuGQ8RGL6ObzYsneAG9Mib1k6zi9Gmj" // console API token + "instill_sk_pgybOAbZmtjB7S5DTDJcmryE7utibLAN" // console API token from http://localhost:3000/settings ); useEffect(() => { - client.Auth.getUserQuery() - .then((data: any) => { - console.log("data", data); - setUser(data); + if (token) { + client.Auth.getUserQuery() + .then((data: any) => { + console.log("data", data); + setUser(data); + }) + .catch((error: any) => { + console.log("error", error); + }); + + client.Pipeline.listPipelinesQuery({ + pageSize: null, + nextPageToken: null, }) - .catch((error: any) => { - console.log("error", error); - }); - - client.Pipeline.listPipelinesQuery({ - pageSize: null, - nextPageToken: null, - }) - .then((data: any) => { - console.log("data", data); - setPipelines(data); - }) - .catch((error: any) => { - console.log("error", error); - }); + .then((data: any) => { + console.log("data", data); + setPipelines(data); + }) + .catch((error: any) => { + console.log("error", error); + }); + } }, []); return ( @@ -122,3 +55,60 @@ export default function TypescriptSdkDemo() { ); } + +// Console Token Implementation + +// import { useEffect, useState } from "react"; +// import InstillClient, { +// Nullable, +// Pipeline, +// User, +// } from "@instill-ai/typescript-sdk"; + +// export default function TypescriptSdkDemo() { +// const [pipelines, setPipelines] = useState([]); +// const [user, setUser] = useState([]); + +// const client = new InstillClient( +// "https://api.instill.tech", +// "v1alpha", +// "instill_sk_OwuGQ8RGL6ObzYsneAG9Mib1k6zi9Gmj" // console API token +// ); + +// useEffect(() => { +// client.Auth.getUserQuery() +// .then((data: any) => { +// console.log("data", data); +// setUser(data); +// }) +// .catch((error: any) => { +// console.log("error", error); +// }); + +// client.Pipeline.listPipelinesQuery({ +// pageSize: null, +// nextPageToken: null, +// }) +// .then((data: any) => { +// console.log("data", data); +// setPipelines(data); +// }) +// .catch((error: any) => { +// console.log("error", error); +// }); +// }, []); + +// return ( +// <> +//

User Data

+//
+//         {JSON.stringify(user, null, 4)}
+//       
+ +//

Pipelines List

+//
+//         {JSON.stringify(pipelines, null, 4)}
+//       
+// +// ); +// } diff --git a/examples/node-app/server.js b/examples/node-app/server.js index 7913c58..52fe600 100644 --- a/examples/node-app/server.js +++ b/examples/node-app/server.js @@ -24,3 +24,32 @@ app.get("/", async (req, res) => { app.listen(port, () => { console.log(`Server is running on port ${port}`); }); + +// Local + +// const express = require("express"); +// const InstillClient = require("@instill-ai/typescript-sdk").default; // If CommonJS style + +// const app = express(); +// const port = 5000; + +// const client = new InstillClient( +// "http://localhost:8080", +// "v1alpha", +// "instill_sk_pgybOAbZmtjB7S5DTDJcmryE7utibLAN" // console API token from http://localhost:3000/settings +// ); + +// // Define a route for listing pipelines using the SDK +// app.get("/", async (req, res) => { +// try { +// const data = await client.Auth.getUserQuery(); +// res.json(data); +// } catch (error) { +// console.error("Error:", error); +// res.status(500).json({ error: "An error occurred" }); +// } +// }); + +// app.listen(port, () => { +// console.log(`Server is running on port ${port}`); +// });