update client

This commit is contained in:
Karamvir
2023-07-20 14:35:51 -07:00
parent 9b656a13e6
commit 09defb60a5
3 changed files with 12 additions and 6 deletions

View File

@@ -1,8 +1,11 @@
{
"name": "monitor_client",
"name": "@monitor/client",
"version": "1.0.0",
"main": "index.js",
"main": "dist/lib.js",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@tanstack/react-query": "^4.29.19",
"axios": "^1.4.0"

View File

@@ -19,8 +19,8 @@ export type LoginOptions = {
secret?: string;
};
export async function MonitorClient(base_url: string) {
let jwt = "";
export function MonitorClient(base_url: string, token?: string) {
let jwt = token ?? "";
const auth = async <R extends AuthRequest>(
request: R
@@ -40,12 +40,14 @@ export async function MonitorClient(base_url: string) {
params: { username: options.username, password: options.password },
});
jwt = res.jwt;
return res.jwt;
} else if (options.secret) {
const res = await auth({
type: "LoginWithSecret",
params: { username: options.username, secret: options.secret },
});
jwt = res.jwt;
return res.jwt;
}
}
};

View File

@@ -2,11 +2,12 @@
"compilerOptions": {
"strict": true,
"target": "ESNext",
"module": "CommonJS",
"module": "ESNext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"outDir": "build"
"outDir": "dist",
"declaration": true
}
}