Skip to content

Commit

Permalink
add test app
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecsl committed Feb 21, 2025
1 parent 9782509 commit 98961f2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ yarn install
yarn build
```

# Running the example app
# Running the test app

```
# if you already have an access token and refresh token
Expand All @@ -32,6 +32,21 @@ DEBUG_DEPTH=5 DEBUG=* \
node dist/example/testApp.js
```

## Running the proxy server

```
node dist/example/wsProxyServer.js
```

## Running the proxy client

```
node dist/example/wsProxyClient.js
> authenticateWithAccessToken {"accessToken":"<auth_token>","refreshToken":"<refresh_token>"}
> quotes ["ABNB", "UBER"]
> accountPositions "1234567890"
```

## Authentication flow

There seems to be currently two ways to authenticate:
Expand Down
44 changes: 44 additions & 0 deletions src/example/wsProxyClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import WebSocket from "ws";
import readline from "readline";

const ws = new WebSocket("ws://localhost:8080");

ws.on("error", console.error);

ws.on("open", function open() {
// Create a readline interface to take user input from the console.
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: "> ",
});
rl.prompt();

// Listen for each line of user input.
rl.on("line", (line) => {
// Trim the input and skip if it's empty.
const trimmedLine = line.trim();
if (trimmedLine.length === 0) {
rl.prompt();
return;
}

// Split the input into parts: first part is the command, the rest are arguments.
const [request, ...args] = trimmedLine.split(" ");
const message = JSON.stringify({
request,
args: JSON.parse(args.join(" ")),
});
ws.send(message);
rl.prompt();
});

rl.on("close", () => {
console.log("Exiting");
process.exit(0);
});
});

ws.on("message", function message(data) {
console.log("received: %s", data);
});
File renamed without changes.
1 change: 1 addition & 0 deletions src/server/wsJsonServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class WsJsonServer implements Disposable {
proxies.push(new WsJsonServerProxy(ws, wsJsonClientFactory));
});
server.listen(port);
logger(`server started and listening on port ${port}`);
}

disconnect() {
Expand Down

0 comments on commit 98961f2

Please sign in to comment.