Skip to content

Commit

Permalink
chore: Namananand/ins 2271 update sdk params (#29)
Browse files Browse the repository at this point in the history
Because

- update SDK params

This commit

- update SDK params
  • Loading branch information
iamnamananand996 authored Oct 6, 2023
1 parent 2079be3 commit c21a9ef
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 92 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ modelDefinitionName,

| function | params |
| :--------------------- | :---------------------: |
| getUserQuery | |
| getUserQuery | |
| checkUserIdExist | id |
| getApiTokenQuery | tokenName |
| listApiTokensQuery | pageSize, nextPageToken |
Expand Down
172 changes: 81 additions & 91 deletions examples/next-app/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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<Pipeline[]>([]);
// const [user, setUser] = useState<User[]>([]);
// const [token, setToken] = useState<Nullable<string>>(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 (
// <>
// <h1>User Data</h1>
// <pre style={{ backgroundColor: "white" }}>
// {JSON.stringify(user, null, 4)}
// </pre>

// <h1>Pipelines List</h1>
// <pre style={{ backgroundColor: "white" }}>
// {JSON.stringify(pipelines, null, 4)}
// </pre>
// </>
// );
// }

// Console Token Implementation

import { useEffect, useState } from "react";
import InstillClient, {
Nullable,
Expand All @@ -78,34 +8,37 @@ import InstillClient, {
export default function TypescriptSdkDemo() {
const [pipelines, setPipelines] = useState<Pipeline[]>([]);
const [user, setUser] = useState<User[]>([]);
const [token, setToken] = useState<Nullable<string>>(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 (
Expand All @@ -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<Pipeline[]>([]);
// const [user, setUser] = useState<User[]>([]);

// 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 (
// <>
// <h1>User Data</h1>
// <pre style={{ backgroundColor: "white" }}>
// {JSON.stringify(user, null, 4)}
// </pre>

// <h1>Pipelines List</h1>
// <pre style={{ backgroundColor: "white" }}>
// {JSON.stringify(pipelines, null, 4)}
// </pre>
// </>
// );
// }
29 changes: 29 additions & 0 deletions examples/node-app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
// });

0 comments on commit c21a9ef

Please sign in to comment.